学生学籍管理系统的设计与实现 下载本文

内容发布更新时间 : 2024/5/5 9:14:38星期一 下面是文章的全部内容请认真阅读。

当删除成功时,弹出窗口:

6.退出

点击,退出学籍管理系统。

5 主要程序代码及说明

1.菜单部分代码:

package XSXJGL;

import java.awt.Container; import java.awt.LayoutManager; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.*;

import javax.swing.JButton; import javax.swing.JFrame;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

public class Menu {

JFrame jf;

JButton j1,j2, j3, j4, j5,j6;

public static void main(String args[]){ Menu m =new Menu(); m.go();

14

}

public void go(){

jf=new JFrame(\学生学籍管理系统\); jf.setBounds(200, 200, 300, 200); Container cp=jf.getContentPane();

cp.setLayout(new FlowLayout(FlowLayout.LEADING,20,20));

j1=new JButton(\添加学生信息\); j2=new JButton(\修改学生信息\); j3=new JButton(\查询学生信息\); j4=new JButton(\删除学生信息\); j5=new JButton(\显示学生信息\); j6=new JButton(\退出管理系统\);

cp.add(j1); cp.add(j2); cp.add(j3); cp.add(j4); cp.add(j5); cp.add(j6);

j1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){ new Add(); } });

j2.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){ Modify modify=new Modify(); } });

j3.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){ Search search=new Search(); } });

15

}

}

j4.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){ Delete delete=new Delete(); } });

j5.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){ Display display=new Display(); } });

j6.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ae){ System.exit(0); } });

jf.setVisible(true);

2.登录部分代码:

package XSXJGL;

import java.awt.Dimension; import java.awt.Toolkit;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener;

import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel;

import javax.swing.JOptionPane; import javax.swing.JPasswordField;

16

import javax.swing.JTextField;

public class Login {

public static void main(String[] args) { final String userName = \; final String passwrod = \;

final JFrame jFrame = new JFrame(\登陆界面\);

Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();

jFrame.setBounds(((int)dimension.getWidth() - 200) / 2, ((int)dimension.getHeight() - 300) / 2, 200, 150);

jFrame.setResizable(false); jFrame.setLayout(null);

jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel label1 = new JLabel(\姓名\); label1.setBounds(10, 10, 100, 30); jFrame.add(label1);

JLabel label2 = new JLabel(\密码\); label2.setBounds(10, 40, 100, 30); jFrame.add(label2);

final JTextField text1 = new JTextField(); text1.setBounds(50, 15, 130, 20); jFrame.add(text1);

final JPasswordField text2 = new JPasswordField(); text2.setBounds(50, 45, 130, 20); jFrame.add(text2);

JButton button = new JButton(\); button.setBounds(10, 75, 170, 40);

button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

if(userName.equals(text1.getText()) && passwrod.equals(text2.getText())) { jFrame.dispose();

JOptionPane.showMessageDialog(null, \登陆成功\, \提示\, JOptionPane.INFORMATION_MESSAGE); jFrame.dispose(); (new Menu()).go(); } else {

17

JOptionPane.showMessageDialog(null, \错误\, \提示\, JOptionPane.ERROR_MESSAGE);

text1.setText(\); text2.setText(\); } } });

jFrame.add(button);

jFrame.setVisible(true);

jFrame.setLocationRelativeTo(null); } }

3.连接数据库部分代码:

package com.microsoft.sqlserver.jdbc;

import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException;

import XSXJGL.Delete;

public class myConnection {

static String url= \; static String user= \;

static String pw= \; static Connection conn ;

public static Connection getmyConnection(){ try {

Class.forName(\);

conn = DriverManager.getConnection(url,user,pw); return conn;

} catch (ClassNotFoundException e) {

e.printStackTrace(); } catch (SQLException e) {

// TODO Auto-generated catch block e.printStackTrace(); }

18