学生学籍管理系统有java源代码
学生信息管理系统JAVA源代码
学生信息管理系统JAVA源代码package stumanage;import javax.swing.*;import java.awt.*;import sun.awt.image.*;import java.awt.event.*;/*** <p>Title: </p>* <p>Description: </p>* <p>Copyright: Copyright (c) 2003</p>* <p>Company: </p>* @author not attributable* @version 1.0*/public class WelcomeFrameextends JFrame {JPanel jPanel1 = new MyPanel();ImageIcon imageIcon1 = new ImageIcon("beautiful.jpg"); BorderLayout borderLayout1 = new BorderLayout();JPanel jPanel2 = new JPanel();GridBagLayout gridBagLayout1 = new GridBagLayout(); JButton jButton1 = new JButton();JButton jButton2 = new JButton();JButton jButton3 = new JButton();JButton jButton4 = new JButton();JButton jButton5 = new JButton();public WelcomeFrame() {try {jbInit();}catch (Exception e) {e.printStackTrace();}}public static void main(String[] args) {WelcomeFrame welcomeFrame = new WelcomeFrame();welcomeFrame.pack();welcomeFrame.show();}private void jbInit() throws Exception {imageIcon1.setDescription("beautiful.jpg");imageIcon1.setImageObserver(this);jPanel1.setLayout(borderLayout1);jPanel1.setMinimumSize(new Dimension(600, 400));jPanel1.setPreferredSize(new Dimension(600, 420));this.setLocale(java.util.Locale.getDefault());this.setResizable(true);this.setSize(new Dimension(747, 396));this.setState(Frame.NORMAL);jPanel2.setBackground(UIManager.getColor("RadioButtonMenuItem.selectionBackgro und"));jPanel2.setForeground(Color.black);jPanel2.setMinimumSize(new Dimension(100, 30));jPanel2.setPreferredSize(new Dimension(100, 400));jPanel2.setLayout(gridBagLayout1);jButton1.setToolTipText(" 个人信息管理");jButton1.setText(" 个人信息管理");jButton1.addActionListener(new WelcomeFrame_jButton1_actionAdapter(this));jButton2.setToolTipText(" 选课信息管理");jButton2.setText(" 选课信息管理");jButton2.addActionListener(new WelcomeFrame_jButton2_actionAdapter(this));jButton3.setToolTipText("奖励信息管理");jButton3.setText("奖励信息管理");jButton3.addActionListener(new WelcomeFrame_jButton3_actionAdapter(this));jButton4.setToolTipText("职务信息管理");jButton4.setText("职务信息管理");jButton4.addActionListener(new WelcomeFrame_jButton4_actionAdapter(this));jButton5.setToolTipText("退出系统");jButton5.setText("退出系统");jButton5.addActionListener(new WelcomeFrame_jButton5_actionAdapter(this));this.getContentPane().add(jPanel1, BorderLayout.CENTER);jPanel1.add(jPanel2, BorderLayout.EAST);jPanel2.add(jButton1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));jPanel2.add(jButton2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(9, 0, 0, 21), 0, 0));jPanel2.add(jButton3, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 0, 0, 10), 0, 0));jPanel2.add(jButton5, new GridBagConstraints(0, 4, 2, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 11), 21, 0));jPanel2.add(jButton4, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(9, 0, 13, 0), 12, 0));}class MyPanelextends JPanel {public void paintComponent(Graphics g) {super.paintComponent(g);imageIcon1.paintIcon(this, g, 0, 0);}}void jButton4_actionPerformed(ActionEvent e) {MainFrame.main( null );this.hide();MainFrame.jTabbedPane1.setSelectedComponent( MainFrame.jPanel4);}void jButton1_actionPerformed(ActionEvent e) {MainFrame.main( null );this.hide();}void jButton3_actionPerformed(ActionEvent e) {MainFrame.main( null );this.hide();MainFrame.jTabbedPane1.setSelectedComponent( MainFrame.jPanel3);}void jButton2_actionPerformed(ActionEvent e) {MainFrame.main( null );this.hide();MainFrame.jTabbedPane1.setSelectedComponent( MainFrame.jPanel2); }void jButton5_actionPerformed(ActionEvent e) {System.exit(0);}}class WelcomeFrame_jButton4_actionAdapter implementsjava.awt.event.ActionListener {WelcomeFrame adaptee;WelcomeFrame_jButton4_actionAdapter(WelcomeFrame adaptee) {this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.jButton4_actionPerformed(e);}}class WelcomeFrame_jButton1_actionAdapter implementsjava.awt.event.ActionListener {WelcomeFrame adaptee;WelcomeFrame_jButton1_actionAdapter(WelcomeFrame adaptee) { this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.jButton1_actionPerformed(e);}}class WelcomeFrame_jButton3_actionAdapter implementsjava.awt.event.ActionListener {WelcomeFrame adaptee;WelcomeFrame_jButton3_actionAdapter(WelcomeFrame adaptee) { this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.jButton3_actionPerformed(e);}}class WelcomeFrame_jButton2_actionAdapter implementsjava.awt.event.ActionListener {WelcomeFrame adaptee;WelcomeFrame_jButton2_actionAdapter(WelcomeFrame adaptee) { this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.jButton2_actionPerformed(e);}}class WelcomeFrame_jButton5_actionAdapter implementsjava.awt.event.ActionListener {WelcomeFrame adaptee;WelcomeFrame_jButton5_actionAdapter(WelcomeFrame adaptee) { this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.jButton5_actionPerformed(e);}}。
java 编写简单的学生信息管理系统--附上源码
学生信息管理系统(Java版)废话不多说,源码如下:源码如下:/*学生信息管理系统,实现学生信息:*增加int[] a=new int[9]*删除*查找*更改*/import java.util.Scanner;//导入java输入流import ng.*;import java.io.*;class Student{private static Student[] s=new Student[2];int n=0;private String name;private int num;private String classAge;public void judge()throws IOException{int i;char ch;String str;Scanner In=new Scanner(System.in);if(n==0){System.out.print("你还没有录入任何学生,是否录入(Y/N):");str=In.next();ch=str.charAt(0);while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n'){System.out.print("输入有误,请重新输入:");str=In.next();ch=str.charAt(0);}if(ch=='Y'||ch=='y'){this.add();}if(ch=='N'||ch=='n'){this.menu();}}}public void menu()throws IOException//定义菜单函数{int a;//定义switch语句变量Scanner in=new Scanner(System.in);//实例化输入流对象System.out.println("*********学生信息管理系统功能表*********"); System.out.println("***** 1.增加*****");System.out.println("***** 2.显示*****");System.out.println("***** 3.修改*****");System.out.println("***** 4.删除*****");System.out.println("***** 5.查看*****");System.out.println("***** 0.退出*****");System.out.println("****************************************"); System.out.print("请选择(0~5):");a=in.nextInt();while(a<0||a>5){System.out.print("输入超出范围,请重新输入:");a=in.nextInt();}switch(a){case 1:this.add();break;case 2:this.show();break;case 3:this.modif();break;case 4:this.delete();break;case 5:this.look();break;case 0:System.exit(0);break;}}public void add()throws IOException//定义增加函数{String str,str1,str2;int i,num1,t=1;char ch,ch1;FileWriter fw=new FileWriter("F://javaFile//student.txt",true);fw.write(" 录入的学生信息列表\r\n\r\n学号姓名班级\r\n"); Scanner In=new Scanner(System.in);while(t==1){System.out.print("请输入学生学号:");num1=In.nextInt();for(i=0;i<n;i++){while(s[i].num==num1){System.out.println("已存在此学号,请重新输入");System.out.print("请输入学号:");num1=In.nextInt();}}s[n].num=num1;str2=String.valueOf(num1);fw.write(str2+" ");System.out.println();System.out.print("请输入学生姓名:");s[n].name=In.next();fw.write(s[n].name+" ");System.out.println();System.out.print("请输入学生班级:");s[n].classAge=In.next();fw.write(s[n].classAge+"\r\n");++n;fw.close();System.out.println();System.out.print("是否继续添加(Y/N)");str=In.next();ch=str.charAt(0);while(ch!='N'&&ch!='n'&&ch!='Y'&&ch!='y'){System.out.print("输入有误,请重新输入:");str=In.next();ch=str.charAt(0);}if(ch=='N'||ch=='n'){break;}}System.out.println();System.out.print("是否返回主菜单(Y/N)");str1=In.next();ch1=str1.charAt(0);while(ch1!='Y'&&ch1!='y'&&ch1!='N'&&ch1!='n'){System.out.print("输入有误,请重新输入:");str1=In.next();ch1=str1.charAt(0);}if(ch1=='Y'||ch1=='y'){this.menu();}if(ch1=='N'||ch1=='n'){System.out.println("正在退出...谢谢使用!");System.exit(0);}}public void show()throws IOException{int i;this.judge();System.out.println("本次操作共录入"+n+"位学生!");System.out.println("你录入的学生信息如下:");System.out.println();System.out.println("学号\t\t姓名\t班级");for(i=0;i<n;i++){System.out.println(s[i].num+" "+s[i].name+" "+s[i].classAge);}System.out.println("系统返回主菜单!");this.menu();}public void delete()throws IOException//删除信息功能实现注:本功能暂时不具备可扩展性{this.judge();int j=0,t=0,k=0,num1;char ch;String str;Scanner pin=new Scanner(System.in);num1=pin.nextInt();for(j=0;j<n;j++){if(s[j].num==num1){k=1;t=j;}}if(k==0){System.out.println("对不起!你要删除的学号不存在!");System.out.println("系统将返回主菜单!");this.menu();}if(k==1){System.out.println("你要删除的学生信息如下:");//打印管理员要删除的学生信息System.out.println("学号\t姓名\t班级");//本功能暂时不备扩展性System.out.println(s[t].num+" "+s[t].name+" "+s[t].classAge);System.out.println();System.out.print("你确定要删除(Y/N):");str=pin.next();ch=str.charAt(0);while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n'){System.out.print("输入有误,请重新输入:");str=pin.next();ch=str.charAt(0);}if(ch=='N'||ch=='n'){System.out.println();System.out.println("系统返回主菜单!");this.menu();}if(ch=='Y'||ch=='y'){for(j=t;j<n-1;j++){s[j]=s[j+1];}n--;System.out.println("系统返回主菜单!");this.menu();}}}public void look()throws IOException{FileReader fr=new FileReader("F://javaFile//student.txt"); int a;while((a=fr.read())!=-1){System.out.print((char)a);}fr.close();System.out.println("系统返回主菜单!");System.out.println();this.menu();}public void modif()throws IOException{this.judge();int j=0,t=0,k=0,num2,num3,moi,c=1;char ch;String str,str1,str2;Scanner pin=new Scanner(System.in);System.out.print("请输入要修改的学号:");num2=pin.nextInt();for(j=0;j<n;j++){if(s[j].num==num2){k=1;t=j;}}if(k==0){System.out.println("对不起!你要修改的学号不存在!"); System.out.println("系统将返回主菜单!");this.menu();}if(k==1){System.out.println("你要修改的学生信息如下:");//打印管理员要删除的学生信息System.out.println("学号\t姓名\t班级");//本功能暂时不备扩展性System.out.println(s[t].num+" "+s[t].name+" "+s[t].classAge);System.out.println();System.out.print("你确定要修改(Y/N):");str=pin.next();ch=str.charAt(0);while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n'){System.out.print("输入有误,请重新输入:");str=pin.next();ch=str.charAt(0);}if(ch=='N'||ch=='n'){System.out.println();System.out.println("系统返回主菜单!");this.menu();}while(c==1){if(ch=='Y'||ch=='y'){System.out.println("****************************************");System.out.println("***** 1.修改学号*****");System.out.println("***** 2.修改班级*****");System.out.println("***** 3.修改姓名*****");System.out.println("****************************************");System.out.print("请选择:");moi=pin.nextInt();switch(moi){case 1:System.out.print("请输入新的学号:");num3=pin.nextInt();s[t].num=num3;break;case 2:System.out.print("请输入新的班级:");str1=pin.next();s[t].classAge=str1;break;case 3:System.out.print("请输入新的姓名:");str2=pin.next();s[t].name=str2;break;}System.out.println("数据已成功修改!");}System.out.print("是否继续修改(Y/N)");str=pin.next();ch=str.charAt(0);System.out.println();while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n'){System.out.print("输入有误,请重新输入:");str=pin.next();ch=str.charAt(0);}if(ch=='N'||ch=='n'){break;}}}System.out.println();System.out.println("系统返回主菜单!");this.menu();}public static void main(String[] args)throws IOException {Student stu=new Student();for(int i=0;i<2;i++){s[i]=new Student();}stu.menu();}}。
java学生管理系统大作业代码
java学生管理系统大作业代码Java学生管理系统是一个基于Java语言开发的学生信息管理系统,用于方便学校教务人员进行学生信息的管理和查询。
以下是该系统的代码实现。
1. 登录界面代码实现该界面是用户登录的入口,用户需要输入用户名和密码才能进入系统。
```javaimport javax.swing.*;import java.awt.*;import java.awt.event.*;public class Login extends JFrame implements ActionListener {JLabel lb1, lb2, lb3;JTextField txtName;JPasswordField txtPwd;JButton btnOK, btnCancel;String userName = "admin";// 默认用户名String password = "123456";// 默认密码public Login() {setTitle("学生信息管理系统登录");// 设置窗体标题setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置窗体关闭方式setSize(350, 200);// 设置窗体大小setLocationRelativeTo(null);// 设置居中显示setLayout(new BorderLayout());JPanel pNorth = new JPanel();lb1 = new JLabel("欢迎使用学生信息管理系统", JLabel.CENTER); lb1.setFont(new Font("微软雅黑", Font.BOLD, 20));pNorth.add(lb1);add(pNorth, BorderLayout.NORTH);JPanel pCenter = new JPanel();pCenter.setLayout(new GridLayout(3, 2));lb2 = new JLabel("用户名:", JLabel.RIGHT);pCenter.add(lb2);txtName = new JTextField(20);pCenter.add(txtName);lb3 = new JLabel("密码:", JLabel.RIGHT);pCenter.add(lb3);txtPwd = new JPasswordField(20);txtPwd.setEchoChar('*');// 设置密码框的回显字符pCenter.add(txtPwd);btnOK = new JButton("登录");pCenter.add(btnOK);btnCancel = new JButton("取消");pCenter.add(btnCancel);add(pCenter, BorderLayout.CENTER);btnOK.addActionListener(this);btnCancel.addActionListener(this);setVisible(true);// 显示窗体}public void actionPerformed(ActionEvent e) {if (e.getSource() == btnOK) {String name = txtName.getText();// 获取用户名String password = new String(txtPwd.getPassword());// 获取密码 if (name.equals(userName) && password.equals(password)) {setVisible(false);new MainFrame();} else {JOptionPane.showMessageDialog(Login.this, "用户名或密码错误!", "登录失败", JOptionPane.ERROR_MESSAGE);}} else if (e.getSource() == btnCancel) {txtName.setText("");txtPwd.setText("");}}public static void main(String[] args) {new Login();}}```2. 主界面代码实现该界面是系统的主界面,包含了菜单栏、工具栏和表格显示区域。
java课程设计学生管理系统源代码
1. MIS_frame类package MIS_Login;import java.awt.Container;import java.awt.Cursor;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent;import javax.swing.ButtonGroup; import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane; import javax.swing.JPanel;import javax.swing.JPasswordField; import javax.swing.JRadioButton;import javax.swing.JTextField;/***总目标:* 1.一个用户名输入框,一个密码输入框* 2.就一个登陆的按钮* 3.加一组JRadioButton ,一个是管理员,一个是学生用户* 4.两个超链接,一个是忘记密码,一个是用户注册**用户注册:* 1.。
只面向的是学生用户,不对管理员开放* 2.注册的时候只有接受协议的时候,才能跳到下一步详细信息的填写。
* 3.包括的信息:学号,姓名,用户名,邮箱名,密码,确认密码,(5)个基本信息,两个按钮,确认与取消* 4.学号必须是系统存在的。
学生信息管理系统源代码java
学生学籍管理系统程序源代码目录1.Client.java (2)2.LoginGUI.java (2)3.AdminGUI.java (6)4.StudentGUI.java (14)5.Select.java (17)6.UpdateAndInsert.java (24)7.Delete.java (27)8.Student.java (29)9.Administrator.java (31)1 / 32程序源代码学生学籍管理系统1.Client.java/*程序入口*/ package ms;public class Client {public static void main(String[] args) {LoginGUI lg=new LoginGUI(); lg.login(); } }2.LoginGUI.java/*登陆主窗口*/ package ms; import java.awt.BorderLayout; import java.awt.Choice; import java.awt.GridLayout; import java.awt.TextField; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; importjava.awt.event.WindowEvent; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; importjavax.swing.JLabel;import javax.swing.JOptionPane; import javax.swing.JPanel; public class LoginGUI {JFrame log=null; //登陆主窗口JPanel jPanel1=null; //用于存放用户名、密码、登录方式标签JPanel jPanel2=null; //用于存放用户名、密码输入框和登录方式选择框JPanel jPanel3=null; //用于存放登陆、退出按钮JLabel jLabel1=null; //用于存放用户名标签JLabel jLabel2=null; //用于存放密码标签JLabel jLabel3=null; //用于存放登录方式标签JLabel jLabel4=null; //学生管理系统登陆标签TextField t1=null; //用于存放用户名输入TextField t2=null; //用于存放密码输入2 / 32程序源代码学生学籍管理系统Choice c=null; //用于存放登录方式选择JButton jB1=null; //登陆按钮JButton jB2=null; //退出按钮String UserName=null; //存放用户输入的用户名String UserPassword=null; //存放用户输入的密码int UserLimit=-1; //存放用户选择登陆权限public LoginGUI() { super();桴獩氮杯?渠睥?牆浡?学生学籍管理系统); this.jPanel1=new JPanel(); this.jPanel2=new JPanel(); this.jPanel3=new JPanel(); ?扡汥?敮??扡汥尨用户名); ?扡汥?敮??扡汥尨密码); ?扡汥?敮??扡汥尨登录方式); jLabel4=new JLabel(new ImageIcon(image/login.jpg)); t1=new TextField(); t2=new TextField();c=new Choice(); //创建一个登录方式下拉选择框?摡?学生登陆); ?摡?管理员登陆); ??敮??瑵潴?登陆); //创建登陆按钮??敮??瑵潴?退出); //创建退出按钮} public void login() { BorderLayout border=new BorderLayout(); border.setVgap(15); border.setHgap(10);log.setLayout(border); //设置登陆主窗口布局管理器为BorderLayout log.add(jPanel1, BorderLayout.WEST); log.add(jPanel2, BorderLayout.CENTER); log.add(jPanel3, BorderLayout.SOUTH);log.add(jLabel4,BorderLayout.NORTH); jPanel1.setLayout(new GridLayout(3,1,30,20)); //3行1列jPanel2.setLayout(new GridLayout(3,1,30,20)); jPanel3.setLayout(new GridLayout(1,2,10,30));3 / 32程序源代码学生学籍管理系统jPanel1.add(jLabel1); //添加三个标签用户名、密码、登陆方式jPanel1.add(jLabel2); jPanel1.add(jLabel3); jPanel2.add(t1);//添加用户名、密码输入文本框登陆方式选择框jPanel2.add(t2); jPanel2.add(c); jPanel3.add(jB1); //添加两个按钮jPanel3.add(jB2); jB1.addActionListener(new ActionListener() { @Overridepublic void actionPerformed(ActionEvent e){ erName=LoginGUI.this.t1.getText(); erPassword=LoginGUI.this.t2.getText();erLimit=LoginGUI.this.c.getSelectedIndex();if(erLimit==0) {StudentGUI ll=newStudentGUI(LoginGUI.this.log,erName);Select sel=new Select(); sel.setStudentList();for(int i=0;i<sel.getStudentAllId().size();i++){ if(sel.getStudentAllId().get(i).toString().equals(er Name)&&sel.getStudentAllPassword().get(i).equals(erPa ssword)){log.setVisible(false); ll.studentGo(); }else if(i==sel.getStudentAllId().size()-1) { 佊瑰潩偮湡?桳睯敍獳条?慩潬?潌楧??琮楨?潬?用户名密码错误);} }4 / 32程序源代码学生学籍管理系统}else if(erLimit==1) { AdminGUIadmin=new AdminGUI(LoginGUI.this.log); Select sel=new Select(); sel.setAdminList();for(int i=0;i<sel.getAdminAllId().size();i++){ if(sel.getAdminAllId().get(i).toString().equals(LoginGUI.this.U serName)&&sel.getAdminAllPassword().get(i).equals(er Password)){log.setVisible(false); admin.adminGo(); }else if(i==sel.getAdminAllId().size()-1) { 佊瑰潩偮湡?桳睯敍獳条?慩潬?潌楧??琮楨?潬?用户名密码错误);} } } } });jB2.addActionListener(new ActionListener() { @Overridepublic void actionPerformed(ActionEvent e) {System.exit(0); } }); log.setSize(240,260);log.setLocationRelativeTo(null); log.setResizable(false);log.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) {System.exit(0);5 / 32程序源代码学生学籍管理系统} }); log.setVisible(true); } }3.AdminGUI.java*/ /*管理员登陆图形界面package ms; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.TextArea; importjava.awt.TextField;import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; importjava.awt.event.WindowEvent; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JDialog; importjavax.swing.JFrame; import javax.swing.JLabel;import javax.swing.JOptionPane; import javax.swing.JPanel; public class AdminGUI {管理员登陆主窗口JDialog log=null;// jp5 用于存放管理员登陆标签和JPanel jp1=null;// 删除按钮增加JPanel jp2=null;// 用于存放查询修改jp5用于存放信息块JPanel jp3=null;//和按钮删除JPanel jp4=null;//用于存放修改插入用于存放请输入学号文本框JPanel jp5=null;// JLabeljadminLog=null; // 管理员登陆标签请输入学号标签JLabel jLabel=null; // 文本框TextField tf=null; //请输入学号JButton jb1=null;//查询按钮JButton jb2=null;//按钮修改按钮增加JButton jb3=null;// 删除按钮JButton jb4=null;// JButton jb5=null; // 列出全部学生信息TextAreata=null;//信息文本框32 / 6程序源代码学生学籍管理系统JLabel jl=null; //用于站位String id=null; // 用于保存用户输入查询学号TextField[] jtf = new TextField[9] ; JDialog jdialog=null;public AdminGUI(JFrame log) {super();桴獩氮杯?渠睥?楄污杯氨杯尬管理员登陆,true); jp1=new JPanel();jp2=new JPanel(); jp3=new JPanel(); jp4=new JPanel(); jp5=new JPanel(); jadminLog=new JLabel(newImageIcon(image/admin.jpg)); ?扡汥渽睥?慌敢?请输入学号); tf=new TextField(); 扪?敮??瑵潴?查询); 扪?敮??瑵潴?修改); 扪?敮??瑵潴?增加); 扪?敮??瑵潴?删除); 扪?敮??瑵潴?列出全部学生信息); 慴渽睥吠硥?敲?点击查询按钮将在此显示查询信息); jl=new JLabel(); } public void adminGo() { BorderLayout bl=new BorderLayout(); bl.setVgap(30); bl.setHgap(30); log.setLayout(bl);log.add(jp1,BorderLayout.NORTH); BorderLayout bl1=new BorderLayout(); bl1.setVgap(20); jp1.setLayout(bl1);jp1.add(jadminLog,BorderLayout.CENTER); jp5.setLayout(newGridLayout(1,2,200,200)); jp5.add(jLabel); jp5.add(tf);32 / 7程序源代码学生学籍管理系统log.add(jp2,BorderLayout.WEST);jp2.setLayout(new GridLayout(2,1,200,300)); jp2.add(jb1);jp2.add(jb5); log.add(jp3,BorderLayout.CENTER);jp3.setLayout(new BorderLayout(10, 10));jp3.add(jp5,BorderLayout.NORTH); jp3.add(ta);jp5.setLayout(new GridLayout(1,5,10,10)); jp5.add(jLabel);jp5.add(tf); log.add(jp4,BorderLayout.SOUTH);jp4.setLayout(new GridLayout(1,3,200,30)); jp4.add(jb2);jp4.add(jb3); jp4.add(jb4); log.addWindowListener(new WindowAdapter() {@Overridepublic void windowClosing(WindowEvent e) {System.exit(0); } }); jb1.addActionListener(new ActionListener() { @Overridepublic void actionPerformed(ActionEvent e) {AdminGUI.this.id=AdminGUI.this.tf.getText(); Select sel=new Select();sel.selectStudent(AdminGUI.this.id); if(sel.getStudent()!=null) {Student student=sel.getStudent();摁業??琮楨?慴献瑥敔瑸尨学号屜屴瑜?姓名屜屴瑜?性别屜屴瑜?出生日期屜屴瑜?民族屜屴瑜?籍贯屜屴瑜?专业屜屴瑜?班级屜屴瑜?联系电话屜屴瑜?密码\t\t); AdminGUI.this.ta.append(\+student.getId()+\ \t+student.getName()+\ \t+student.getSex()+\ \t+student.getBornDate()+\ \t+student.getNationality()+\ \t+student.getNationality()+\ \t+student.getMaj()+\+student.getCla()+\ \t+student.getTelNum()+\ \t+student.getPa8 / 32程序源代码学生学籍管理系统ssword()+\); } else {摁業??琮楨?慴献瑥敔瑸尨查无此人); } } });jb5.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {Select sel=new Select(); sel.selectAllStudent();摁業??琮楨?慴献瑥敔瑸尨学号屜屴瑜?姓名屜屴瑜?性别屜屴瑜?出生日期屜屴瑜?民族屜屴瑜?籍贯屜屴瑜?专业屜屴瑜?班级屜屴瑜?联系电话屜屴瑜?密码\t\t\n);for(int i=0;i<sel.getAllStudent().size();i++) {Student student=sel.getAllStudent().get(i);AdminGUI.this.ta.append(student.getId()+\ \t+student.getName()+\\t+student.getSex()+\ \t+student.getBornDate()+\ \t+student.getNationality()+\ \t+student.getHometown()+\ \t+student.getMaj()+\ +student.getCla()+\\t+student.getTelNum()+\ \t+student.getPassword()+\); } } }); log.setSize(850,580);log.setLocationRelativeTo(null); log.setResizable(false);jb3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e){ jdialog=new JDialog(AdminGUI.this.log); String[] str=new 瑓楲杮嵛屻姓名?性别?出生日期?民族?籍贯?专业?班级?联系电话?密码};JLabel[] jlabel=new JLabel[9]; for(int i=0;i<9;i++)9 / 32程序源代码学生学籍管理系统{jlabel[i]=new JLabel(str[i]); jtf[i]=new TextField(); }JPanel jpanel1=new JPanel(); JPanel jpanel2=new JPanel(); ?瑵潴?扪瑵潴?渽睥?畂瑴湯尨确定); ?瑵潴?扪瑵潴?渽睥?畂瑴湯尨取消); jdialog.setLayout(new BorderLayout());jdialog.add(jpanel1,BorderLayout.CENTER);jdialog.add(jpanel2,BorderLayout.SOUTH);jpanel1.setLayout(new GridLayout(9,2,10,10)); for(int i=0;i<9;i++) {jpanel1.add(jlabel[i]); jpanel1.add(jtf[i]); } jpanel2.add(jbutton1); jpanel2.add(jbutton2);jbutton1.addActionListener(new ActionListener(){ @Overridepublic void actionPerformed(ActionEvent e) {Student student=new Student();student.setName(AdminGUI.this.jtf[0].getText());student.setSex(AdminGUI.this.jtf[1].getText());student.setBornDate(AdminGUI.this.jtf[2].getText()); student.setNationality(AdminGUI.this.jtf[3].getText()); student.setHometown(AdminGUI.this.jtf[4].getText());student.setMaj(AdminGUI.this.jtf[5].getText()); student.setCla(AdminGUI.this.jtf[6].getText());student.setTelNum(AdminGUI.this.jtf[7].getText()); student.setPassword(AdminGUI.this.jtf[8].getText()); UpdateAndInsert up=new UpdateAndInsert();if(up.insertStudent(student)==true) {32 / 10程序源代码学生学籍管理系统佊瑰潩偮湡?桳睯敍獳条?慩潬?摁業??琮楨?潬?添加成功); } jdialog.dispose(); } });jbutton2.addActionListener(new ActionListener(){ @Overridepublic void actionPerformed(ActionEvent e) {jdialog.dispose(); } });jdialog.setSize(500,400);jdialog.setLocationRelativeTo(null); jdialog.setResizable(false); jdialog.setVisible(true); } }); jb4.addActionListener(new ActionListener() { @Overridepublic void actionPerformed(ActionEvent e) {if(new Delete().delete(AdminGUI.this.tf.getText())==true) {佊瑰潩偮湡?桳睯敍獳条?慩潬?摁業??琮楨?潬?刪除成功);}else 佊瑰潩偮湡?桳睯敍獳条?慩潬?摁業??琮楨?潬?刪除失敗); } }); jb2.addActionListener(new ActionListener(){ @Overridepublic void actionPerformed(ActionEvent e) {Select sel=new Select();AdminGUI.this.id=AdminGUI.this.tf.getText();sel.selectStudent(AdminGUI.this.tf.getText());11 / 32程序源代码学生学籍管理系统Student student=sel.getStudent(); if(student==null) {佊瑰潩偮湡?桳睯敍獳条?慩潬?摁業??琮楨?潬?请检查输入的学号); } else {jdialog=new JDialog(AdminGUI.this.log); String[] str=new瑓楲杮嵛屻姓名?性别?出生日期?民族?籍贯?专业?班级?联系电话?密码};JLabel[] jlabel=new JLabel[9]; for(int i=0;i<9;i++) {jlabel[i]=new JLabel(str[i]); } jtf[0]=new TextField(student.getName()); jtf[1]=newTextField(student.getSex());jtf[2]=new TextField(student.getBornDate()); jtf[3]=new TextField(student.getNationality()); jtf[4]=newTextField(student.getHometown()); jtf[5]=newTextField(student.getMaj()); jtf[6]=new TextField(student.getCla());jtf[7]=new TextField(student.getTelNum()); jtf[8]=new TextField(student.getPassword()); JPanel jpanel1=new JPanel(); JPanel jpanel2=new JPanel(); ?瑵潴?扪瑵潴?渽睥?畂瑴湯尨确定); ?瑵潴?扪瑵潴?渽睥?畂瑴湯尨取消);jdialog.setLayout(new BorderLayout());jdialog.add(jpanel1,BorderLayout.CENTER);jdialog.add(jpanel2,BorderLayout.SOUTH); jpanel1.setLayout(new GridLayout(9,2,10,10)); for(int i=0;i<9;i++) {jpanel1.add(jlabel[i]); jpanel1.add(jtf[i]); }jpanel2.add(jbutton1); jpanel2.add(jbutton2);jbutton1.addActionListener(new ActionListener()12 / 32程序源代码学生学籍管理系统{ @Overridepublic void actionPerformed(ActionEvent e) {Student student=new Student(Integer.parseInt(AdminGUI.this.id), jtf[0].getText(), jtf[1].getText(), jtf[2].getText(), jtf[3].getText(),jtf[4].getText(), jtf[5].getText(), jtf[6].getText(), jtf[7].getText(),jtf[8].getText());UpdateAndInsert up=new UpdateAndInsert();if(up.updateStudent(student)==true) { 佊瑰潩偮湡?桳睯敍獳条?慩潬?摁業??琮楨?潬?更改成功);; }jdialog.dispose(); } });jbutton2.addActionListener(new ActionListener(){ @Overridepublic void actionPerformed(ActionEvent e) {jdialog.dispose(); } });jdialog.setSize(500,400);jdialog.setLocationRelativeTo(null); jdialog.setResizable(false); jdialog.setVisible(true); } } });log.setVisible(true); } }13 / 32程序源代码学生学籍管理系统4.StudentGUI.java*/ /*学生操作图形界面package ms; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.TextField;import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import java.awt.event.WindowAdapter; importjava.awt.event.WindowEvent; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JDialog; importjavax.swing.JFrame; import javax.swing.JLabel;import javax.swing.JOptionPane; import javax.swing.JPanel; public class StudentGUI {学生登入类主窗口JDialog log=null;// 用于存放登入块JPaneljp1=null;// JPanel jp2=null;// 用于存放信息块用于密码存放修改块JPanel jp3=null;// 用于存放我的信息按钮JPanel jp4=null;// JLabel jl1=null;// 学生登入标签学号标签JLabel jl2=null;// 学生姓名标签JLabeljl3=null;// 性别标签JLabel jl4=null;// 出生日期标签JLabel jl5=null;// JLabel jl6=null;//民族标签JLabel jl7=null;// 籍贯标签JLabel jl8=null;// 专业标签班级标签JLabel jl9=null;// JLabel jl10=null;// 联系电话标签请输入密码标签JLabel jl11=null;// JButton jb1=null;//我的信息按钮JButton jb2=null;//密码修改按钮TextField t1=null;//学号文本框学生姓名文本框TextField t2=null;// TextField t3=null;//性别文本框出生日期文本框TextField t4=null;//32 / 14程序源代码学生学籍管理系统TextField t5=null;//民族文本框籍贯文本框TextField t6=null;//专业文本框TextField t7=null;// TextField t8=null;//班级文本框联系电话文本框TextField t9=null;// TextField t10=null;//密码文本框存放密码输入框JPanel jp5=new JPanel();// String id=null;public StudentGUI(JFrame log,String str) {super();桴獩氮杯?渠睥?楄污杯氨杯尬学生登入,true); jp1=new JPanel();jp2=new JPanel(); jp3=new JPanel(); jp4=new JPanel();jl1=new JLabel(new ImageIcon(image/student.jpg)); :); 汪?敮??扡汥尨学号学生姓名:); 汪?敮??扡汥尨性别:); 汪?敮??扡汥尨出生日期汪?敮??扡汥尨:); 民族:); 汪?敮??扡汥尨汪?敮??扡汥尨籍贯:); 汪?敮??扡汥尨专业:); :); 汪?敮??扡汥尨班级:); 联系电话汪?渽睥?慌敢? :);请输入新密码汪?渽睥?慌敢? ); 我的信息扪?敮??瑵潴? ); 扪?敮??瑵潴? 密码修改t1=new T extField(); t2=new TextField(); t3=new TextField(); t4=new TextField(); t5=new TextField(); t6=new TextField(); t7=new TextField(); t8=new TextField(); t9=new TextField(); t10=new TextField(); this.id=str; } public void studentGo() {BorderLayout bl=new BorderLayout(); bl.setHgap(30);bl.setVgap(30);32 / 15程序源代码学生学籍管理系统log.setLayout(bl);log.add(jp1,BorderLayout.NORTH);//将登入块信息块密码修改块放入主窗口log.add(jp2,BorderLayout.CENTER);log.add(jp3,BorderLayout.SOUTH); log.add(jp4,BorderLayout.WEST);jp1.add(jl1,BorderLayout.CENTER); jp2.setLayout(newGridLayout(5,2,20,10)); jp2.add(jl2); jp2.add(t1); jp2.add(jl3);jp2.add(t2); jp2.add(jl4); jp2.add(t3); jp2.add(jl5); jp2.add(t4);jp2.add(jl6); jp2.add(t5); jp2.add(jl7); jp2.add(t6); jp2.add(jl8); jp2.add(t7); jp2.add(jl9); jp2.add(t8); jp2.add(jl10); jp2.add(t9); jp4.add(jb1); BorderLayout bl1=new BorderLayout();bl1.setHgap(38); jp3.setLayout(bl1);jp3.add(jb2,BorderLayout.WEST);jp3.add(jp5,BorderLayout.CENTER); jp5.setLayout(new GridLayout()); jp5.add(jl11); jp5.add(t10);jb1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {Select sel=new Select(); sel.selectStudent(id);Student student=sel.getStudent();t1.setText(new Integer(student.getId()).toString());t2.setText(student.getName()); t3.setText(student.getSex());32 / 16程序源代码学生学籍管理系统t4.setText(student.getBornDate());t5.setText(student.getNationality());t6.setText(student.getHometown()); t7.setText(student.getMaj());t8.setText(student.getCla());t9.setText(student.getTelNum()); } });jb2.addActionListener(new ActionListener() { @Overridepublic void actionPerformed(ActionEvent e) {String password=StudentGUI.this.t10.getText(); UpdateAndInsert up=new UpdateAndInsert();if(up.updatePassword(id, password)==true) { 佊瑰潩偮湡?桳睯敍獳条?慩潬?瑓摵湥??琮楨?潬? 修改成功); } } });log.addWindowListener(new WindowAdapter() {@Overridepublic void windowClosing(WindowEvent e) {System.exit(0); } }); log.setSize(550,420);log.setLocationRelativeTo(null); log.setResizable(false);log.setVisible(true); } }5.Select.java/* 查询类包括查询的各种方法*/ package ms;import java.sql.*; import java.util.LinkedList;17 / 32程序源代码学生学籍管理系统public class Select {private LinkedList<Integer> studentAllId=null;private LinkedList<String> studentAllPassword=null; private LinkedList<Integer> adminAllId=null;private LinkedList<String> adminAllPassword=null; private Student student=null;private LinkedList<Student> allStudent=null; // 定义MySQL的数据库驱动程序public static final String DBDRIVER =org.gjt.mm.mysql.Driver ; // 定义MySQL数据库的连接地址public static final String DBURL =jdbc:mysql://localhost:3306/studentMS ; 数据库的连接用户名// MySQLpublic static final String DBUSER =oot ; 数据库的连接密码// MySQLpublic static final String DBPASS = systemout ; public Select() {super();this.studentAllId = new LinkedList<Integer>();this.studentAllPassword = new LinkedList<String>(); this.adminAllId = new LinkedList<Integer>();this.adminAllPassword = new LinkedList<String>();this.allStudent = new LinkedList<Student>(); } public LinkedList<Integer> getStudentAllId() {return studentAllId; } public LinkedList<String> getStudentAllPassword() {return studentAllPassword; }public LinkedList<Integer> getAdminAllId() {return adminAllId; }public LinkedList<String> getAdminAllPassword() {return adminAllPassword; }public Student getStudent() {32 / 18程序源代码学生学籍管理系统return student; }public LinkedList<Student> getAllStudent() {return allStudent; } public void setStudentList() //设置studentAllId 和studentAllPassword {Connection conn = null ; // 数据库连接Statement stmt = null ; // 数据库的操作对象ResultSet rs = null ; // 保存查询结果String sql = select id,password from student; try{Class.forName(DBDRIVER) ; // 加载驱动程序}catch(ClassNotFoundException e){ e.printStackTrace() ; }try{conn =DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; }catch(SQLE xception e){ e.printStackTrace() ; } try {stmt = conn.createStatement() ; //得到stmt对象用于执行sql语句} catch (SQLException e1) { e1.printStackTrace(); } try { rs = stmt.executeQuery(sql) ;//保存sql查询结果} catch (SQLException e1) {e1.printStackTrace(); } try {while(rs.next()) {studentAllId.add(rs.getInt(1));studentAllPassword.add(rs.getString(2)); }} catch (SQLException e1) {e1.printStackTrace();19 / 32程序源代码学生学籍管理系统} try{rs.close() ; stmt.close() ;conn.close() ; // 数据库关闭}catch(SQLExceptione){ e.printStackTrace() ; } } public void setAdminList() { Connection conn = null ; // 数据库连接Statement stmt = null ; // 数据库的操作对象ResultSet rs = null ; // 保存查询结果String sql = select id,password from admin; try{Class.forName(DBDRIVER) ; // 加载驱动程序}catch(ClassNotFoundException e){ e.printStackTrace() ; }try{conn =DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; }catch(SQLE xception e){ e.printStackTrace() ; } try {stmt = conn.createStatement() ; //得到stmt对象用于执行sql语句} catch (SQLException e1) {e1.printStackTrace(); } try {rs = stmt.executeQuery(sql) ;//保存sql查询结果} catch (SQLException e1) {e1.printStackTrace(); } try {while(rs.next()) {adminAllId.add(rs.getInt(1));adminAllPassword.add(rs.getString(2)); }} catch (SQLException e1) {20 / 32程序源代码学生学籍管理系统e1.printStackTrace(); } try{rs.close() ; stmt.close() ;conn.close() ; // 数据库关闭}catch(SQLExceptione){ e.printStackTrace() ; } } public boolean selectStudent(String str) {Connection conn = null ; // 数据库连接PreparedStatement pstmt = null ; // 数据库的操作对象ResultSet rs = null ; // 保存查询结果String sql = selectname,sex,bornDate,nationality,hometown,maj,cla,telNum,password +rom student where id=?; try{Class.forName(DBDRIVER) ; // 加载驱动程序}catch(ClassNotFoundException e){ e.printStackTrace() ; }try{conn =DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; }catch(SQLE xception e){ e.printStackTrace() ; } try {pstmt = conn.prepareStatement(sql) ; //得到stmt对象用于执行sql语句} catch (SQLException e1) { e1.printStackTrace(); } try {pstmt.setString(1, str); } catch (SQLException e2) {e2.printStackTrace(); } try {rs = pstmt.executeQuery() ;//保存sql查询结果} catch (SQLException e1) {e1.printStackTrace(); }21 / 32程序源代码学生学籍管理系统try {while(rs.next()) {student=new Student(Integer.parseInt(str), rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4),rs.getString(5), rs.getString(6), rs.getString(7),rs.getString(8), rs.getString(9)); }} catch (SQLException e1) {e1.printStackTrace(); } try{rs.close() ; pstmt.close() ;conn.close() ; // 数据库关闭}catch(SQLExceptione){ e.printStackTrace() ; }if(student !=null) {return true; } else {return false; } } public void selectAllStudent(){ Connection conn = null ; // 数据库连接PreparedStatement pstmt = null ; // 数据库的操作对象ResultSet rs = null ; // 保存查询结果String sql = select * +rom student; try{Class.forName(DBDRIVER) ; // 加载驱动程序}catch(ClassNotFoundException e){ e.printStackTrace() ; }try{conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;32 / 22程序源代码学生学籍管理系统}catch(SQLException e){ e.printStackTrace() ; } try {pstmt = conn.prepareStatement(sql) ; //得到stmt对象用于执行sql语句} catch (SQLException e1) { e1.printStackTrace(); }try {rs = pstmt.executeQuery() ;//保存sql 查询结果} catch (SQLException e1) {e1.printStackTrace(); } try {while(rs.next()) {student=new Student(rs.getInt(1), rs.getString(2),rs.getString(3), rs.getString(4), rs.getString(5),rs.getString(6), rs.getString(7), rs.getString(8),rs.getString(9), rs.getString(10));allStudent.add(student); }} catch (SQLException e1) {e1.printStackTrace(); } try{rs.close() ; pstmt.close() ;conn.close() ; // 数据库关闭}catch(SQLExceptione){ e.printStackTrace() ; } } }32 / 23程序源代码学生学籍管理系统6.UpdateAndInsert.java/*修改&&插入类定义了修改和插入的所有方法*/ package ms; import java.sql.Connection; import java.sql.DriverManager; importjava.sql.SQLException; import java.sql.Statement; public class UpdateAndInsert {// 定义MySQL的数据库驱动程序public static final String DBDRIVER = org.gjt.mm.mysql.Driver ; // 定义MySQL数据库的连接地址public static final String DBURL = jdbc:mysql://localhost:3306/studentMS ; // MySQL数据库的连接用户名public static final String DBUSER =oot ; // MySQL数据库的连接密码public static final String DBPASS = systemout ; public boolean insertStudent (Student student) { String name=student.getName(); String sex=student.getSex(); String bornDate=student.getBornDate(); Stringnationality=student.getNationality(); Stringhometown=student.getHometown(); String maj=student.getMaj(); String cla=student.getCla();String telNum=student.getTelNum(); Stringpassword=student.getPassword(); Connection conn = null ; // 数据库连接Statement stmt = null ; // 数据库操作try { Class.forName(DBDRIVER) ;} catch (ClassNotFoundException e) {// TODO Auto-generated catch block e.printStackTrace(); } // 加载驱动程序String sql = INSERT INTOstudent(name,sex,bornDate,nationality,hometown,maj,cla,telNum,passw ord) +VALUES24 / 32程序源代码学生学籍管理系统('+name+','+sex+','+bornDate+','+nationality+','+hometown+','+maj+', '+cla+','+telNum+','+password+'); try {conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); }try {stmt = conn.createStatement() ; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace();对象实例化} Statement // try {stmt.executeUpdate(sql) ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace();// } 执行数据库更新操作try {关闭操作// stmt.close() ; conn.close() ;} catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); // 数据库关闭} return true; } public boolean updateStudent(Student student) {Select sel=new Select(); if(sel.selectStudent(newInteger(student.getId()).toString())==false) {return false; }数据库连接// Connection conn = null ; // 数据库操作Statement stmt = null ; String name=student.getName(); Stringsex=student.getSex();32 / 25程序源代码学生学籍管理系统String bornDate=student.getBornDate(); Stringnationality=student.getNationality(); String hometown=student.getHometown(); String maj=student.getMaj(); Stringcla=student.getCla();String telNum=student.getTelNum(); Stringpassword=student.getPassword(); String sql=UPDATE student SET name='+name+',sex='+sex+',bornDate='+bornDate+',nationality='+na tionality+',hometown='+hometown+',maj='+maj+',cla='+cla+',telNum ='+telNum+',password='+password+' WHERE id=+student.getId() ;try {= conn DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; } catch (SQLException e1) {// TODO Auto-generated catch block e1.printStackTrace(); }try {stmt = conn.createStatement() ; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace();Statement// 实例化对象} try {stmt.executeUpdate(sql) ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace();// } 执行数据库更新操作try {// 关闭操作stmt.close() ; // 数据库关闭conn.close() ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); } return true; }32 / 26程序源代码学生学籍管理系统public boolean updatePassword(String id,String newPassword) { Connection conn = null ; // 数据库连接Statement stmt = null ; // 数据库操作String sql=UPDATE student SETpassword='+newPassword+' WHERE id=+id ; try {conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; } catch (SQLException e1) {// TODO Auto-generated catch block e1.printStackTrace(); }try {stmt = conn.createStatement() ; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace();Statement 对象// 实例化} try {stmt.executeUpdate(sql) ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace();执行数据库更新操作} // try {关闭操作// stmt.close() ; conn.close() ; 数据库关闭// } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); } return true; } }7.Delete.java/* 删除类*/* 定义了删除的所有方法32 / 27程序源代码学生学籍管理系统package ms; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class Delete {// 定义MySQL的数据库驱动程序public static final String DBDRIVER = org.gjt.mm.mysql.Driver ; // 定义MySQL数据库的连接地址public static final String DBURL = jdbc:mysql://localhost:3306/studentMS ; //MySQL数据库的连接用户名public static final String DBUSER =oot ; // MySQL数据库的连接密码public static final String DBPASS = systemout ; public boolean delete (String str) {Select sel=new Select();if(sel.selectStudent(str)==false) {return false; }Connection conn = null ; // 数据库连接Statement stmt = null ; // 数据库操作int id = Integer.parseInt(str) ; try {Class.forName(DBDRIVER) ;} catch (ClassNotFoundException e) {// TODO Auto-generated catch block e.printStackTrace(); } // 加载驱动程序String sql = DELETE FROM student WHERE id=+id ; try {conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); }try {stmt = conn.createStatement() ; } catch (SQLException e) {// TODO Auto-generated catch block28 / 32程序源代码学生学籍管理系统e.printStackTrace();} // 实例化Statement对象try {stmt.executeUpdate(sql) ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace();} // 执行数据库更新操作try {stmt.close() ; // 关闭操作conn.close() ; // 数据库关闭} catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); } return true; }}8.Student.java/*学生类*/ package ms; public class Student {private int id=0; //用于存放学号private String name=null; //用于存放学生姓名private String sex=null; //用于存放性别private String bornDate=null; //出生年日期private String nationality=null; //民族private String hometown=null; //用于存放籍贯private String maj=null; //用于存放专业private String cla=null; //用于存放班级private String telNum=null; //用于存放联系电话private String password=null; //用于存放密码public Student(int id, String name, String sex, String bornDate, String nationality, String hometown, String maj, String cla, String telNum, String password) { this.id = id; = name; this.sex = sex;this.bornDate = bornDate; this.nationality = nationality;this.hometown = hometown; this.maj = maj;。
Java课程设计_学籍管理系统代码
//Student_Management_System.java//JHelpTextPanel.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.io.*;//定义帮助文档类class JHelpTextPanel extends JPanel{Font newSmallTitleFont=new Font("楷体",Font.BOLD,12);JTextArea HelpText=new JTextArea();JHelpTextPanel(){setLayout(null);setBackground(Color.orange);HelpText.setBackground(Color.orange);HelpText.setForeground(Color.red);HelpText.setFont(newSmallTitleFont);HelpText.setBounds(0,0,600,600);add(HelpText);}}//Student_InforPanel .javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.io.*;class Student_InforPanel extends JPanel implements ActionListener {//四种常用字体的定义Font newTitleFont=new Font("楷体",Font.BOLD,40);Font newSmallTitleFont=new Font("楷体",Font.BOLD,25);Font newCommonFont=new Font("宋体",Font.BOLD,20);Font newSubMenuFont=new Font("宋体",Font.BOLD,15);Font NewSubMenuFont=new Font("宋体",Font.BOLD,10);//性别数组定义String os[]={" 男 "," 女 "};//定义确认对话框图标ImageIcon thinker=new ImageIcon("ICON//thinker.gif");//定义学生信息管理系统面板菜单控件JLabel StudentSno_Clue=new JLabel("学号:");JLabel StudentName_Clue=new JLabel("姓名:");JLabel StudentSex_Clue=new JLabel("性别:");JLabel StudentAge_Clue=new JLabel("年龄:");JLabel StudentClass_Clue=new JLabel("班级:");JLabel StudentDept_Clue=new JLabel("系别:");JTextField StudentSno_Input=new JTextField();JTextField StudentName_Input=new JTextField();ComboBoxModel Othermode=new OtherAModel();JComboBox StudentSex_Input=new JComboBox(Othermode);JTextField StudentAge_Input=new JTextField();JTextField StudentClass_Input=new JTextField();JTextField StudentDept_Input=new JTextField();JTextArea QueryInforShow=new JTextArea();JLabel QueryClue=new JLabel("以下是你要查询的学生信息:"); JButton Add_StudentInformation=new JButton("增加学生信息");JButton Del_StudentInformation=new JButton("删除学生信息");JButton Query_StudentInformation=new JButton("查询学生信息");JButton Modify_StudentInformation=new JButton("修改学生信息");//定义变量int ValidAge;String SnoOrigin;Student_InforPanel(){setBackground(Color.orange);QueryInforShow.setBackground(Color.orange);setLayout(null);StudentSno_Clue.setBounds(270,120,80,30);StudentSno_Clue.setFont(newCommonFont);StudentSno_Input.setBounds(350,120,120,30);StudentName_Clue.setBounds(270,170,80,30);StudentName_Clue.setFont(newCommonFont);StudentName_Input.setBounds(350,170,120,30);StudentSex_Clue.setBounds(270,220,80,30);StudentSex_Clue.setFont(newCommonFont);StudentSex_Input.setBounds(350,220,120,30);StudentAge_Clue.setBounds(270,270,80,30);StudentAge_Clue.setFont(newCommonFont);StudentAge_Input.setBounds(350,270,120,30); StudentClass_Clue.setBounds(270,320,80,30); StudentClass_Clue.setFont(newCommonFont);StudentClass_Input.setBounds(350,320,120,30); StudentDept_Clue.setBounds(270,370,80,30);StudentDept_Clue.setFont(newCommonFont);StudentDept_Input.setBounds(350,370,120,30);Query_StudentInformation.setBounds(80,120,130,30); Query_StudentInformation.setFont(newSubMenuFont);Query_StudentInformation.addActionListener(this); QueryClue.setBounds(80,180,300,50);QueryClue.setFont(newSubMenuFont);QueryInforShow.setBounds(80,220,530,100); QueryInforShow.setFont(newSubMenuFont);Del_StudentInformation.setBounds(80,120,130,30);Del_StudentInformation.setFont(newSubMenuFont);Del_StudentInformation.addActionListener(this);Add_StudentInformation.setBounds(80,170,130,30);Add_StudentInformation.setFont(newSubMenuFont);Add_StudentInformation.addActionListener(this);Modify_StudentInformation.setBounds(80,220,130,30); Modify_StudentInformation.setBounds(80,220,130,30); Modify_StudentInformation.setFont(newSubMenuFont); Modify_StudentInformation.addActionListener(this);add(StudentSno_Clue);add(StudentSno_Input);add(StudentName_Clue);add(StudentName_Input);add(StudentSex_Clue);add(StudentSex_Input);add(StudentAge_Clue);add(StudentAge_Input);add(StudentClass_Clue);add(StudentClass_Input);add(StudentDept_Clue);add(StudentDept_Input);add(QueryClue);add(QueryInforShow);add(Add_StudentInformation);add(Del_StudentInformation);add(Query_StudentInformation);add(Modify_StudentInformation);}public void actionPerformed(ActionEvent e){if(e.getSource()==Add_StudentInformation){if(IsValidAge(StudentAge_Input.getText())){String ***=(String)StudentSex_Input.getSelectedItem();MainMenu.myDatabase.Add_Database_Information(StudentSno_Input.ge tText(),StudentName_Input.getText(),***,ValidAge,StudentClass_Input.getT ext(),StudentDept_Input.getText());emptyInput();}}if(e.getSource()==Del_StudentInformation){QueryInforShow.setText("");if(MainMenu.myDatabase.Query_Database_Information(Studen tSno_Input.getText())){QueryInforShow.setText(DataBaseControl.temptInformation);int result=JOptionPane.showConfirmDialog(null,"你确定要删除该生信息吗?","ConfirmMessage",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,think er);if(result==JOptionPane.YES_OPTION){if(MainMenu.myDatabase.Del_Database_Information(St udentSno_Input.getText()))JOptionPane.showMessageDialog(null,"删除操作成功!","Happy Message",JOptionPane.PLAIN_MESSAGE);elseJOptionPane.showMessageDialog(null,"数据库操作出现异常,删除操作失败!","Error Message",JOptionPane.ERROR_MESSAGE);}}elseQueryInforShow.setText("对不起,没有找到你要删除的学生信息.");}if(e.getSource()==Query_StudentInformation){QueryInforShow.setText("");if(MainMenu.myDatabase.Query_Database_Information(Stud entSno_Input.getText()))QueryInforShow.setText(DataBaseControl.temptInformatio n);elseQueryInforShow.setText("对不起,没有你想要查询的学生信息");}if(e.getSource()==Modify_StudentInformation){if(IsValidAge(StudentAge_Input.getText()))MainMenu.myDatabase.Modify_Database_Information(SnoOri gin,StudentSno_Input.getText(),StudentName_Input.getText(),ValidAge,StudentClass_Inpu t.getText(),StudentDept_Input.getText());}}public boolean IsValidAge(String StringAge){try{ValidAge=Integer.parseInt(StringAge);}catch(NumberFormatException e){e.printStackTrace();return false;}if(ValidAge<=120&ValidAge>0)return true;else{JOptionPane.showMessageDialog(null,"你输入的年龄不合实际情况\n 请重新输入!","WARNING MESSAGE",JOptionPane.WARNING_MESSAGE);return false;}}class OtherAModel extends DefaultComboBoxModel{OtherAModel(){for(int i=0;i<os.length;i++)addElement(os[i]);}}public void emptyInput(){StudentSno_Input.setText("");StudentAge_Input.setText("");StudentName_Input.setText("");StudentClass_Input.setText("");StudentDept_Input.setText("");}public void OnlyShowSno(){StudentSno_Clue.setVisible(true);StudentSno_Input.setVisible(true);StudentSno_Input.setText("");QueryClue.setVisible(true);QueryInforShow.setVisible(true);StudentName_Clue.setVisible(false);StudentName_Input.setVisible(false);StudentSex_Clue.setVisible(false);StudentSex_Input.setVisible(false);StudentAge_Clue.setVisible(false);StudentAge_Input.setVisible(false);StudentClass_Clue.setVisible(false);StudentClass_Input.setVisible(false);StudentDept_Clue.setVisible(false);StudentDept_Input.setVisible(false);}//显示学生信息的所有面板控件public void ShowWhole(){StudentSno_Clue.setVisible(true);StudentSno_Input.setVisible(true);StudentSno_Input.setText("");QueryClue.setVisible(false);QueryInforShow.setVisible(false);StudentName_Clue.setVisible(true);StudentName_Input.setVisible(true);StudentName_Input.setText("");StudentSex_Clue.setVisible(true);StudentSex_Input.setVisible(true);StudentAge_Clue.setVisible(true);StudentAge_Input.setVisible(true);StudentAge_Input.setText("");StudentClass_Clue.setVisible(true);StudentClass_Input.setVisible(true);StudentClass_Input.setText("");StudentDept_Clue.setVisible(true);StudentDept_Input.setVisible(true);StudentDept_Input.setText("");}}//Student_ScorePanel.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;class Student_ScorePanel extends JPanel implements ActionListener {//三种常用字体的定义Font newTitleFont=new Font("楷体",Font.BOLD,40);Font newSmallTitleFont=new Font("楷体",Font.BOLD,25);Font newCommonFont=new Font("宋体",Font.BOLD,20);Font newSubMenuFont=new Font("宋体",Font.BOLD,15);Font NewSubMenuFont=new Font("宋体",Font.BOLD,10);//定义确认对话框图标ImageIcon thinker=new ImageIcon("ICON//thinker.gif");JLabel ScoreSno_Clue=new JLabel("学号:");JLabel ScoreEnglish_Clue=new JLabel("英语:");JLabel ScoreSeniorMath_Clue=new JLabel("高数:");JLabel ScoreC_Clue=new JLabel("C:");JLabel ScoreVC_Clue=new JLabel("VC:");JLabel ScoreJAVA_Clue=new JLabel("JAVA:");JTextField ScoreSno_Input=new JTextField();JTextField ScoreEnglish_Input=new JTextField();JTextField ScoreSeniorMath_Input=new JTextField();JTextField ScoreC_Input=new JTextField();JTextField ScoreVC_Input=new JTextField();JTextField ScoreJAVA_Input=new JTextField();JTextArea ScoreShow=new JTextArea();JLabel ScoreShowClue=new JLabel("你要查询的学生成绩信息为:");JButton Add_ScoreInformation=new JButton("增加学生成绩");JButton Del_ScoreInformation=new JButton("删除学生成绩");JButton Query_ScoreInformation=new JButton("查询学生成绩");JButton Modify_ScoreInformation=new JButton("修改学生成绩");//定义变量int ValidScore;String ScoreSno;Student_ScorePanel(){//学生成绩管理面板设置控件setBackground(Color.orange);ScoreShow.setBackground(Color.orange);setLayout(null);ScoreSno_Clue.setBounds(270,120,80,30);ScoreSno_Clue.setFont(newCommonFont);ScoreSno_Input.setBounds(350,120,120,30);ScoreEnglish_Clue.setBounds(270,170,80,30);ScoreEnglish_Clue.setFont(newCommonFont);ScoreEnglish_Input.setBounds(350,170,120,30);ScoreSeniorMath_Clue.setBounds(270,220,80,30); ScoreSeniorMath_Clue.setFont(newCommonFont); ScoreSeniorMath_Input.setBounds(350,220,120,30);ScoreC_Clue.setBounds(270,270,80,30);ScoreC_Clue.setFont(newCommonFont);ScoreC_Input.setBounds(350,270,120,30);ScoreVC_Clue.setBounds(270,320,80,30);ScoreVC_Clue.setFont(newCommonFont);ScoreVC_Input.setBounds(350,320,120,30);ScoreJAVA_Clue.setBounds(270,370,80,30);ScoreJAVA_Clue.setFont(newCommonFont);ScoreJAVA_Input.setBounds(350,370,120,30);Query_ScoreInformation.setBounds(80,120,130,30);Query_ScoreInformation.setFont(newSubMenuFont);Query_ScoreInformation.addActionListener(this); ScoreShowClue.setFont(newSubMenuFont);ScoreShowClue.setBounds(80,180,300,50);ScoreShow.setFont(newSubMenuFont);ScoreShow.setBounds(80,220,530,100);Del_ScoreInformation.setBounds(80,120,130,30);Del_ScoreInformation.setFont(newSubMenuFont);Del_ScoreInformation.addActionListener(this);Add_ScoreInformation.setBounds(80,170,130,30);Add_ScoreInformation.setFont(newSubMenuFont);Add_ScoreInformation.addActionListener(this);Modify_ScoreInformation.setBounds(80,220,130,30);Modify_ScoreInformation.setFont(newSubMenuFont);Modify_ScoreInformation.addActionListener(this);add(ScoreSno_Clue);add(ScoreSno_Input);add(ScoreEnglish_Clue);add(ScoreEnglish_Input);add(ScoreSeniorMath_Clue);add(ScoreC_Clue);add(ScoreSeniorMath_Input);add(ScoreC_Input);add(ScoreVC_Clue);add(ScoreVC_Input);add(ScoreJAVA_Clue);add(ScoreJAVA_Input);add(ScoreShow);add(ScoreShowClue);add(Add_ScoreInformation);add(Del_ScoreInformation);add(Query_ScoreInformation);add(Modify_ScoreInformation);}public void actionPerformed(ActionEvent e){if(e.getSource()==Query_ScoreInformation)//查询按纽事件触发处理{if(MainMenu.myDatabase.QueryScoreFunction(ScoreSno_Input.getText ())){ScoreShow.setText("");ScoreShow.append("学号\t\t英语\t高数\tC\tVC\tJAVA\n");ScoreShow.append(MainMenu.myDatabase.Student_Score[MainMenu.my Database.NowScoreNum]);}else{ScoreShow.setText("");ScoreShow.setText("对不起,没有你想要查找的学生信息!");}}if(e.getSource()==Add_ScoreInformation)//增加学生成绩信息按纽的时间触发{if(IsValidScore(ScoreEnglish_Input.getText())&&IsValidScore(Scor eSeniorMath_Input.getText())&&IsValidScore(ScoreC_Input.getText())&&IsValidScore(ScoreVC_Input.getText()) &&IsValidScore(ScoreJAVA_Input.getText())){IsValidScore(ScoreEnglish_Input.getText());int englishscore=ValidScore;IsValidScore(ScoreSeniorMath_Input.getText());int seniorscore=ValidScore;IsValidScore(ScoreC_Input.getText());int cscore=ValidScore;IsValidScore(ScoreVC_Input.getText());int vcscore=ValidScore;IsValidScore(ScoreJAVA_Input.getText());int javascore=ValidScore;MainMenu.myDatabase.addStudentScoreInformation(ScoreSno_Inpu t.getText(),englishscore,seniorscore, cscore, vcscore, javascore);emptyInput();}}if(e.getSource()==Del_ScoreInformation)//删除学生成绩信息事件触发处理{if(MainMenu.myDatabase.QueryScoreFunction(ScoreSno_Input.getText ())){ScoreShow.setText("");ScoreShow.append("学号\t\t英语\t高数\tC\tVC\tJAVA\n");ScoreShow.append(MainMenu.myDatabase.Student_Score[MainMenu.my Database.NowScoreNum]);int result=JOptionPane.showConfirmDialog(null,"你真的要删除该学生的成绩信息吗?","Confirm Message",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,thinker);if(result==JOptionPane.YES_OPTION)MainMenu.myDatabase.DelScoreFunction(ScoreSno_Input.getText( ));}else{ScoreShow.setText("");ScoreShow.setText("对不起,你要删除的学生成绩信息不存在!");}}if(e.getSource()==Modify_ScoreInformation)//修改数据库中学生成绩信息事件的触发{if(IsValidScore(ScoreEnglish_Input.getText())&&IsValidScore(Scor eSeniorMath_Input.getText())&&IsValidScore(ScoreC_Input.getText())&&IsValidScore(ScoreVC_Input.getT ext())&&IsValidScore(ScoreJAVA_Input.getText())){IsValidScore(ScoreEnglish_Input.getText());int englishscore=ValidScore;IsValidScore(ScoreSeniorMath_Input.getText());int seniorscore=ValidScore;IsValidScore(ScoreC_Input.getText());int cscore=ValidScore;IsValidScore(ScoreVC_Input.getText());int vcscore=ValidScore;IsValidScore(ScoreJAVA_Input.getText());int javascore=ValidScore;MainMenu.myDatabase.ModifyStudentScoreInformation(Scor eSno_Input.getText(),ScoreSno,englishscore,seniorscore, cscore, vcscore, javascore);emptyInput();}}}public boolean IsValidScore(String stringAge)//判断成绩输入是否合法{try{ValidScore=Integer.parseInt(stringAge);}catch(NumberFormatException e){JOptionPane.showMessageDialog(null,"成绩输入中含有非法字符!","ERROR MESSAGE",JOptionPane.ERROR_MESSAGE);return false;}if(ValidScore>100||ValidScore<0){JOptionPane.showMessageDialog(null,"分数只能在0~100之间的整数!","ERROR MESSAGE",JOptionPane.ERROR_MESSAGE);return false;}return true;}//只显示学生成绩面板中学号相关控件public void ScoreShowOnlySno(){ScoreSno_Clue.setVisible(true);ScoreSno_Input.setVisible(true);ScoreSno_Input.setText("");ScoreShowClue.setVisible(true);ScoreShow.setVisible(true);ScoreEnglish_Clue.setVisible(false);ScoreEnglish_Input.setVisible(false);ScoreEnglish_Input.setText("");ScoreSeniorMath_Clue.setVisible(false);ScoreSeniorMath_Input.setVisible(false);ScoreSeniorMath_Input.setText("");ScoreC_Clue.setVisible(false);ScoreC_Input.setVisible(false);ScoreC_Input.setText("");ScoreVC_Clue.setVisible(false);ScoreVC_Input.setVisible(false);ScoreVC_Input.setText("");ScoreJAVA_Clue.setVisible(false);ScoreJAVA_Input.setVisible(false);ScoreJAVA_Input.setText("");}public void emptyInput()//清空成绩输入控件{ScoreSno_Input.setText("");ScoreEnglish_Input.setText("");ScoreSeniorMath_Input.setText("");ScoreC_Input.setText("");ScoreVC_Input.setText("");ScoreJAVA_Input.setText("");}//显示学生成绩面板中所有控件public void ScoreShowWhole(){ScoreSno_Clue.setVisible(true);ScoreSno_Input.setVisible(true);ScoreShowClue.setVisible(false);ScoreShow.setVisible(false);ScoreEnglish_Clue.setVisible(true);ScoreEnglish_Input.setVisible(true);ScoreSeniorMath_Clue.setVisible(true);ScoreSeniorMath_Input.setVisible(true);ScoreC_Clue.setVisible(true);ScoreC_Input.setVisible(true);ScoreVC_Clue.setVisible(true);ScoreVC_Input.setVisible(true);ScoreJAVA_Clue.setVisible(true);ScoreJAVA_Input.setVisible(true);}}//DataBaseControl.javaimport java.awt.*;import javax.swing.*;import java.io.*;import java.sql.*;import java.awt.event.*;import java.util.*;//数据库操作class DataBaseControl{//private String s="";//登录用户信息String UserRealName;String UserSex;int UserAge;String UserClass;String UserDept;//类中公有变量类型变量String LoginName="";String PW="";int Rank;final int MaxNum=20;String Student_Information[]=new String[MaxNum];String Student_Score[]=new String[MaxNum];String[] Database_Score={"学号","英语","高数","C","VC","JAVA"}; String[] Database_Information={"学号","姓名","性别","年龄","班级","系别"};int NowScoreNum;int NowInformationNum;static String temptInformation="";private Connection con1;private Statement st1;String str;public void init(String UserName,String PassWord,int i){LoginName=UserName;PW=PassWord;Rank=i;}public boolean ConnectDataBase()//连接数据源{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("Driver not found!");return false;}try{con1=DriverManager.getConnection("jdbc:odbc:学生管理数据库");st1=con1.createStatement();}catch(SQLException e){System.out.println("Data Source not found!");return false;}return true;}public int QueryUserLogin()//用户身份验证{int i=0;if(ConnectDataBase()){try{ResultSet rs1=st1.executeQuery("select* from UserLogin where 用户名='"+LoginName+"'");while(rs1.next()){if((rs1.getString(3).equals(PW))&&(rs1.getInt(4) ==Rank)){JOptionPane.showMessageDialog(null,"登录成功!\n"+rs1.getString(2)+"欢迎你使用学生管理系统","Happy Message",JOptionPane.PLAIN_MESSAGE);if(Rank==1)return 1;elsereturn 2;}//end-ifi++;}//end-whileif(i==0){JOptionPane.showMessageDialog(null,"该用户不存在!","Error Message",JOptionPane.ERROR_MESSAGE);}else{JOptionPane.showMessageDialog(null,"你的密码或者用户登级有误!","Error Message",JOptionPane.ERROR_MESSAGE);}Close_database();}catch(SQLException e1){System.out.println(e1.toString());return 0;}}//end-ifreturn 0;}public void ChangeUserPW(String newPW)//修改用户密码{if(ConnectDataBase()){try{st1.executeUpdate("UPDATE UserLogin SET 用户密码='"+newPW+"' where 用户名='"+LoginName+"'");Close_database();}catch(SQLException e){System.out.println(e.toString());JOptionPane.showMessageDialog(null,"对数据库操作发生错误!","ERROR MESSAGE",JOptionPane.ERROR_MESSAGE);return;}JOptionPane.showMessageDialog(null,"修改密码成功!\n请记住你的新密码.","SucessfulMessage",JOptionPane.PLAIN_MESSAGE);}}public void ShowUserInformation()//显示用户信息{if(ConnectDataBase()){try{ResultSet sr=st1.executeQuery("select* from UserBasicInformation where 用户名='"+LoginName+"'");while(sr.next()){UserRealName=sr.getString(2);UserSex=sr.getString(3);UserAge=sr.getInt(4);UserClass=sr.getString(5);UserDept=sr.getString(6);}Close_database();}catch(SQLException e){System.out.println("Error!!");}}//end-if}public void DeleteUser()//注销帐户{String str1;if(ConnectDataBase()){try{str1="DELETE FROM UserLogin where 用户名='"+LoginName+"'";str="DELETE FROM UserBasicInformation where 用户名='"+LoginName+"'";st1.executeUpdate(str1);st1.executeUpdate(str);Close_database();//关闭数据库连接}catch(SQLException e){System.out.println("Error!!");}}JOptionPane.showMessageDialog(null,"注销帐户成功!","HappyMessage",JOptionPane.PLAIN_MESSAGE);}///////////////////////////////////////学生信息处理函数//////////////////////////////////////////////////////public void show_DataBase_Information()//显示数据库中学生的个人基本信息{String Information;if(ConnectDataBase()){try{str="SELECT* FROM Student_Basic_Information";ResultSet s1=st1.executeQuery(str);int i=0;while(s1.next()){if(i>MaxNum)break;Information=s1.getString(1)+"\t"+s1.getString(2)+"\t"+s1.g etString(3)+"\t"+s1.getLong(4)+"\t"+s1.getString(5)+"\t"+s1.getString(6)+"\n";Student_Information[i]=Information;i++;}NowInformationNum=i;Close_database();}catch(SQLException e){System.out.println(e.toString());}}}public boolean Query_Database_Information(String sno)//显示查询数据库中学生信息{if(ConnectDataBase()){try{str="select* from Student_Basic_Information where 学号='"+sno+"'";ResultSet s1=st1.executeQuery(str);int i=0;while(s1.next()){temptInformation=s1.getString(1)+"\t"+s1.getString(2)+"\t" +s1.getString(3)+"\t"+s1.getLong(4)+"\t"+s1.getString(5)+"\t"+s1.getString(6)+"\n";i++;}Close_database();if(i>0)return true;}catch(SQLException e){e.printStackTrace();return false;}}return false;}public void Add_Database_Information(String sno,String name,String ***,int age,String classname,String dept){//向数据库中加入新生的基本信息if(ConnectDataBase()){try{str="INSERT INTOStudent_Basic_Information"+"(学号,姓名,性别,年龄,班级,系别)";str=str+"VALUES('"+sno+"','"+name+"',' "+***+"',"+age+",'"+classname+"','"+dept+"')";st1.executeUpdate(str);Close_database();}catch(SQLException e){e.printStackTrace();return;}JOptionPane.showMessageDialog(null,"加入新生记录操作成功!","HAPPY MESSAGE",JOptionPane.PLAIN_MESSAGE);}}public boolean Del_Database_Information(String sno)//删除数据库中某个学生的基本信息{if(ConnectDataBase()){try{str="DELETE FROM Student_Basic_Information WHERE 学号='"+sno+"'";st1.executeUpdate(str);Close_database();}catch(SQLException e){e.printStackTrace();return false;}return true;}return false;}public void Modify_Database_Information(String sno,Stringsno1,String name,int age,String classname,String dept){//修改数据库中学生基本信息if(ConnectDataBase()){try{str="update Student_Basic_Information set 学号='"+sno1+"' where 学号='"+sno+"'";st1.executeUpdate(str);str="update Student_Basic_Information set 姓名='"+name+"' where 学号='"+sno1+"'";st1.executeUpdate(str);str="update Student_Basic_Information set 年龄="+age+" where 学号='"+sno1+"'";st1.executeUpdate(str);str="update Student_Basic_Information set 班级='"+classname+"' where 学号='"+sno1+"'";st1.executeUpdate(str);str="update Student_Basic_Information set 系别='"+dept+"' where 学号='"+sno1+"'";st1.executeUpdate(str);Close_database();}catch(SQLException e){e.printStackTrace();return;}JOptionPane.showMessageDialog(null,"修改学生信息记录操作成功!","HAPPY MESSAGE",JOptionPane.PLAIN_MESSAGE);}}////////////////////////////////////////学生成绩函数///////////////////////////////////////////////public void show_DataBase_Score()//显示数据库中学生的成绩信息{String score;if(ConnectDataBase()){try{int i=0;str="SELECT* FROM StudentScore";ResultSet s2=st1.executeQuery(str);while(s2.next()){if(i>MaxNum)break;score=s2.getString(1)+"\t"+s2.getLong(2)+"\t"+s2.g etLong(3)+"\t"+s2.getLong(4)+"\t"+s2.getLong(5)+"\t"+s2.getLong(6)+"\n";Student_Score[i]=score;i++;}NowScoreNum=i;Close_database();}catch(SQLException e){System.out.println(e.toString());}}}public boolean QueryScoreFunction(String SnoN){//根据学号查询学生的成绩信息String score;boolean find=false;if(ConnectDataBase()){try{str="SELECT* FROM StudentScore WHERE 学号='"+SnoN+"'";ResultSet s2=st1.executeQuery(str);while(s2.next()){find=true;score=s2.getString(1)+"\t"+s2.getLong(2)+"\t"+s2.getLong (3)+"\t"+s2.getLong(4)+"\t"+s2.getLong(5)+"\t"+s2.getLong(6);Student_Score[NowScoreNum]=score;}Close_database();}catch(SQLException e){e.printStackTrace();}}if(find)return true;elsereturn false;}public void addStudentScoreInformation(String sno,int englishscore,int seniorscore,int cscore,int vcscore,int javascore){//加入学生的成绩信息if(ConnectDataBase()){try{str="INSERT INTO StudentScore"+"(学号,英语,高数,C,VC,JAVA)";str=str+"VALUES('"+sno+"',"+englishscore+","+seniorscore+","+cscore+","+vcscore+","+javascore+")";st1.executeUpdate(str);Close_database();}catch(SQLException e){JOptionPane.showMessageDialog(null,"数据库操作发生异常\n加入学生成绩记录操作失败!","ERROR MESSAGE",JOptionPane.ERROR_MESSAGE);return;}JOptionPane.showMessageDialog(null,"加入新生记录操作成功!","HAPPY MESSAGE",JOptionPane.PLAIN_MESSAGE);}}public void DelScoreFunction(String sno){//删除学生的成绩信息if(ConnectDataBase()){try{str="DELETE FROM StudentScore WHERE 学号='"+sno+"'";st1.executeUpdate(str);}catch(SQLException e){JOptionPane.showMessageDialog(null,"数据库操作发生异常\n删除学生成绩记录操作失败!","ERROR MESSAGE",JOptionPane.PLAIN_MESSAGE);return;}JOptionPane.showMessageDialog(null,"删除学生成绩记录操作成功!","HAPPY MESSAGE",JOptionPane.PLAIN_MESSAGE);}}public void ModifyStudentScoreInformation(String sno1,String sno,int englishscore,int seniorscore,int cscore,int vcscore,int javascore)//修改数据库中学生成绩信息{if(ConnectDataBase()){try{str="update StudentScore set 学号='"+sno1+"' where 学号='"+sno+"'";st1.executeUpdate(str);str="update StudentScore set 英语="+englishscore+" where 学号。
Java版学籍管理系统源代码
Java版学籍管理系统源代码package 学籍管理系统;/** To change this template, choose Tools | Templates* and open the template in the editor.*//**** @author Administrator*/import java.awt.*;import t.*;import javax.swing.*;import java.io.*;import java.util.*;public class Delete extends JPanel implements ActionListener/****/private static final long serialVersionUID 1L; Hashtable 基本信息表 null;JTextField 学号,姓名,专业,年级,出生;JRadioButton 男,女;JButton 删除;ButtonGroup group null;FileInputStream inOne null;ObjectInputStream inTwo null;FileOutputStream outOne null;ObjectOutputStream outTwo null;File file null; public Delete File filethis.file file;学号 new JTextField 10 ;删除 new JButton "删除" ;学号.addActionListener this ;删除.addActionListener this ;姓名 new JTextField 10 ;姓名.setEditable false ;专业 new JTextField 10 ;专业.setEditable false ;年级 new JTextField 10 ;年级.setEditable false ;出生 new JTextField 10 ;出生.setEditable false ;男 new JRadioButton "男",false ;女 new JRadioButton "女",false ;group new ButtonGroup ;group.add 男 ;group.add 女 ;Box box1 Box.createHorizontalBox ;box1.add new JLabel "输入要删除的学号:",JLabel.CENTER ; box1.add 学号 ;box1.add 删除 ;Box box2 Box.createHorizontalBox ;box2.add new JLabel "姓名:",JLabel.CENTER ;box2.add 姓名 ;Box box3 Box.createHorizontalBox ;box3.add new JLabel "性别:",JLabel.CENTER ;box3.add 男 ;box3.add 女 ;Box box4 Box.createHorizontalBox ;box4.add new JLabel "专业:",JLabel.CENTER ;box4.add 专业 ;Box box5 Box.createHorizontalBox ; box5.add new JLabel "年级:",JLabel.CENTER ;box5.add 年级 ;Box box6 Box.createHorizontalBox ; box6.add new JLabel "出生:",JLabel.CENTER ;box6.add 出生 ;Box boxH Box.createVerticalBox ; boxH.add box1 ;boxH.add box2 ;boxH.add box3 ;boxH.add box4 ;boxH.add box5 ;boxH.add box6 ;boxH.add Box.createVerticalGlue ;JPanel pCenter new JPanel ;pCenter.add boxH ;setLayout new BorderLayout ;add pCenter,BorderLayout.CENTER ;validate ;public void actionPerformed ActionEvent eif e.getSource 删除||e.getSource 学号String number "";number 学号.getText ;if number.length 0tryinOne new FileInputStream file ;inTwo new ObjectInputStream inOne ;基本信息表 Hashtable inTwo.readObject ; inOne.close ;inTwo.close ;catch Exception eeif 基本信息表.containsKey numberStudent stu Student 基本信息表.get number ;姓名.setText stu.getName ;专业.setText stu.getDisciping ;年级.setText stu.getGrade ;出生.setText stu.getBorth ;if stu.getSex .equals "男"男.setSelected true ;else女.setSelected true ;String m "确定要删除该学号及全部信息吗?";int ok JOptionPane.showConfirmDialog this,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE ;if ok JOptionPane.YES_OPTION基本信息表.remove number ;tryoutOne new FileOutputStream file ;outTwo new ObjectOutputStream outOne ;outTwo.writeObject 基本信息表 ;outTwo.close ;outOne.close ;学号.setText null ;姓名.setText null ;专业.setText null ;年级.setText null ;出生.setText null ;catch Exception eeSytln ee ;else if ok JOptionPane.NO_OPTION学号.setText null ;姓名.setText null ;专业.setText null ;年级.setText null ;出生.setText null ;elseString warning "该学号不存在!";JOptionPane.showMessageDialog this,warning,"警告",JOptionPane.WARNING_MESSAGE ;elseString warning "必须要输入学号!";JOptionPane.showMessageDialog this,warning,"警告",JOptionPane.WARNING_MESSAGE ;package 学籍管理系统;/** To change this template, choose Tools | Templates* and open the template in the editor.*//**** @author Administrator*/import java.awt.*;import t.*;import javax.swing.*;import java.io.*;import java.util.*;public class Inquest extends JDialog implements ActionListener/****/private static final long serialVersionUID 1L;Hashtable 基本信息表 null;JTextField 学号,姓名,专业,年级,出生;JRadioButton 男,女;JButton 查询;ButtonGroup group null;FileInputStream inOne null;ObjectInputStream inTwo null;File file null; public Inquest JFrame f,File filesuper f,"查询对话框",false ; this.file file;学号 new JTextField 10 ;查询 new JButton "查询" ;学号.addActionListener this ;查询.addActionListener this ;姓名 new JTextField 10 ;姓名.setEditable false ;专业 new JTextField 10 ;专业.setEditable false ;年级 new JTextField 10 ;年级.setEditable false ;出生 new JTextField 10 ;出生.setEditable false ;男 new JRadioButton "男",false ;女 new JRadioButton "女",false ;group new ButtonGroup ;group.add 男 ;group.add 女 ;Box box1 Box.createHorizontalBox ;box1.add new JLabel "输入要查询的学号:",JLabel.CENTER ; box1.add 学号 ;box1.add 查询 ;Box box2 Box.createHorizontalBox ;box2.add new JLabel "姓名:",JLabel.CENTER ;box2.add 姓名 ;Box box3 Box.createHorizontalBox ;box3.add new JLabel "性别:",JLabel.CENTER ;box3.add 男 ;box3.add 女 ;Box box4 Box.createHorizontalBox ;box4.add new JLabel "专业:",JLabel.CENTER ;box4.add 专业 ;Box box5 Box.createHorizontalBox ;box5.add new JLabel "年级:",JLabel.CENTER ;box5.add 年级 ;Box box6 Box.createHorizontalBox ;box6.add new JLabel "出生:",JLabel.CENTER ;box6.add 出生 ;Box boxH Box.createVerticalBox ;boxH.add box1 ;boxH.add box2 ;boxH.add box3 ;boxH.add box4 ;boxH.add box5 ;boxH.add box6 ;boxH.add Box.createVerticalGlue ;JPanel pCenter new JPanel ;pCenter.add boxH ;Container con getContentPane ;con.add pCenter,BorderLayout.CENTER ;con.validate ;setVisible false ;setBounds 100,200,360,270 ;addWindowListener new WindowAdapterpublic void windowClosing WindowEvent e setVisible false ;;public void actionPerformed ActionEvent e姓名.setText null ;专业.setText null ;年级.setText null ;出生.setText null ;if e.getSource 查询||e.getSource 学号String number "";number 学号.getText ;if number.length 0tryinOne new FileInputStream file ;inTwo new ObjectInputStream inOne ;基本信息表 Hashtable inTwo.readObject ; inOne.close ;inTwo.close ;catch Exception eeif 基本信息表.containsKey numberStudent stu Student 基本信息表.get number ;姓名.setText stu.getName ;专业.setText stu.getDisciping ;年级.setText stu.getGrade ;出生.setText stu.getBorth ;if stu.getSex .equals "男"男.setSelected true ;else女.setSelected true ;elseString warning "该学号不存在!";JOptionPane.showMessageDialog this,warning,"警告",JOptionPane.WARNING_MESSAGE ;elseString warning "必须要输入学号!";JOptionPane.showMessageDialog this,warning,"警告",JOptionPane.WARNING_MESSAGE ;package 学籍管理系统;/** To change this template, choose Tools | Templates* and open the template in the editor.*//**** @author Administrator*/import java.awt.*;import t.*;import javax.swing.*;import java.io.*;import java.util.*;public class ModifySituation extends JPanel implements ActionListener/****/private static final long serialVersionUID 1L;Hashtable 基本信息表 null;JTextField 学号,姓名,专业,年级,出生;JRadioButton 男,女;ButtonGroup group null;JButton 开始修改,录入修改,重置;FileInputStream inOne null;ObjectInputStream inTwo null;FileOutputStream outOne null;ObjectOutputStream outTwo null;File file null;public ModifySituation File filethis.file file;学号 new JTextField 10 ;姓名 new JTextField 10 ;专业 new JTextField 10 ;年级 new JTextField 10 ;出生 new JTextField 10 ;group new ButtonGroup ;男 new JRadioButton "男",true ;女 new JRadioButton "女",false ;group.add 男 ;group.add 女 ;开始修改 new JButton "开始修改" ;录入修改 new JButton "录入修改" ;录入修改.setEnabled false ;重置 new JButton "重置" ;学号.addActionListener this ;开始修改.addActionListener this ;录入修改.addActionListener this ;重置.addActionListener this ;Box box1 Box.createHorizontalBox ;box1.add new JLabel "输入要修改信息的学号:",JLabel.CENTER ; box1.add 学号 ;box1.add 开始修改 ;Box box2 Box.createHorizontalBox ;box2.add new JLabel " 新姓名:",JLabel.CENTER ;box2.add 姓名 ;Box box3 Box.createHorizontalBox ; box3.add new JLabel " 新性别:",JLabel.CENTER ; box3.add 男 ;box3.add 女 ;Box box4 Box.createHorizontalBox ; box4.add new JLabel " 新专业:",JLabel.CENTER ; box4.add 专业 ;Box box5 Box.createHorizontalBox ; box5.add new JLabel " 新年级:",JLabel.CENTER ; box5.add 年级 ;Box box6 Box.createHorizontalBox ; box6.add new JLabel " 新出生:",JLabel.CENTER ; box6.add 出生 ;Box boxH Box.createVerticalBox ; boxH.add box1 ;boxH.add box2 ;boxH.add box3 ;boxH.add box4 ;boxH.add box5 ;boxH.add box6 ;boxH.add Box.createVerticalGlue ;JPanel pCenter new JPanel ;pCenter.add boxH ;setLayout new BorderLayout ;add pCenter,BorderLayout.CENTER ;JPanel pSouth new JPanel ;pSouth.add 录入修改 ;pSouth.add 重置 ;add pSouth,BorderLayout.SOUTH ;validate ;public void actionPerformed ActionEvent eif e.getSource 开始修改||e.getSource 学号String number "";number 学号.getText ;if number.length 0tryinOne new FileInputStream file ;inTwo new ObjectInputStream inOne ;基本信息表 Hashtable inTwo.readObject ;inOne.close ;inTwo.close ;catch Exception eeif 基本信息表.containsKey number录入修改.setEnabled true ;Student stu Student 基本信息表.get number ;姓名.setText stu.getName ;专业.setText stu.getDisciping ;年级.setText stu.getGrade ;出生.setText stu.getBorth ;if stu.getSex .equals "男"男.setSelected true ;else女.setSelected true ;else录入修改.setEnabled false ;String warning "该学号不存在!";JOptionPane.showMessageDialog this,warning,"警告",JOptionPane.WARNING_MESSAGE ;学号.setText null ;姓名.setText null ;专业.setText null ;年级.setText null ;出生.setText null ;else录入修改.setEnabled false ;String warning "必须要输入学号!";JOptionPane.showMessageDialog this,warning,"警告",JOptionPane.WARNING_MESSAGE ;学号.setText null ;姓名.setText null ;专业.setText null ;年级.setText null ;出生.setText null ;else if e.getSource 录入修改String number "";number 学号.getText ;if number.length 0tryinOne new FileInputStream file ;inTwo new ObjectInputStream inOne ;基本信息表 Hashtable inTwo.readObject ; inOne.close ;inTwo.close ;catch Exception eeif 基本信息表.containsKey numberString question "该生基本信息已存在,您想修改他她的基本信息吗?";JOptionPane.showMessageDialog this,question,"警告",JOptionPane.QUESTION_MESSAGE ;String m "基本信息将被修改!";int ok JOptionPane.showConfirmDialog this,m,"确认",JOptionPane.YES_NO_OPTION,RMATION_MESSAGE ;if ok JOptionPane.YES_OPTIONString name 姓名.getText ;String discipling 专业.getText ;String grade 年级.getText ;String borth 出生.getText ;String sex null;if 男.isSelectedsex 男.getText ;elsesex 女.getText ;Student 学生 new Student ;学生.setNumber number ;学生.setName name ;学生.setDiscipling discipling ;学生.setGrade grade ;学生.setBorth borth ;学生.setSex sex ;tryoutOne new FileOutputStream file ;outTwo new ObjectOutputStream outOne ;基本信息表.put number,学生 ;outTwo.writeObject 基本信息表 ;outTwo.close ;outOne.close ;学号.setText null ;姓名.setText null ;专业.setText null ;年级.setText null ;出生.setText null ;catch Exception eeSytln ee ;录入修改.setEnabled false ;else if ok JOptionPane.NO_OPTION录入修改.setEnabled true ;elseString warning "该学号没有基本信息,不能修改!";JOptionPane.showMessageDialog this,warning,"警告",JOptionPane.WARNING_MESSAGE ;录入修改.setEnabled false ;elseString warning "必须要输入学号!";JOptionPane.showMessageDialog this,warning,"警告",JOptionPane.WARNING_MESSAGE ;录入修改.setEnabled false ;if e.getSource 重置学号.setText null ;姓名.setText null ;专业.setText null ;年级.setText null ;出生.setText null ;package 学籍管理系统;/** To change this template, choose Tools | Templates* and open the template in the editor.*//**** @author Administrator*/public class Student implements alizable/****/private static final long serialVersionUID 1L; String number,name,discipling,grade,borth,sex;public Studentpublic void setNumber String numberthis.number number;public String getNumberreturn number;public void setName String name name;public String getNamereturn name;public void setDiscipling String discipling this.discipling discipling;public String getDiscipingreturn discipling;public void setGrade String gradethis.grade grade;public String getGradereturn grade;public void setBorth String borththis.borth borth;public String getBorthreturn borth;public void setSex String sexthis.sex sex;public String getSexreturn sex;package 学籍管理系统;/** To change this template, choose Tools | Templates* and open the template in the editor.*//**** @author Administrator*/import java.awt.*;import t.*;import javax.swing.*;import java.io.*;import table;public class StudentManager extends JFrame implements ActionListener/****/private static final long serialVersionUID 1L; StudentSituation 基本信息录入 null;ModifySituation 基本信息修改 null;Inquest 基本信息查询 null;Delete 基本信息删除 null;JMenuBar bar;JMenu fileMenu;JMenuItem 录入,修改,查询,删除;Container con null;Hashtable ?, ? 基本信息 null; File file null;CardLayout card null;JLabel label null;JPanel pCenter;public StudentManager录入 new JMenuItem "录入学生基本信息" ;修改 new JMenuItem "修改学生基本信息" ;查询 new JMenuItem "查询学生基本信息" ;删除 new JMenuItem "删除学生基本信息" ;bar new JMenuBar ;fileMenu new JMenu "菜单选项" ;fileMenu.add 录入 ;fileMenu.add 修改 ;fileMenu.add 查询 ;fileMenu.add 删除 ;bar.add fileMenu ;setJMenuBar bar ;label new JLabel "欢迎使用学生基本信息管理系统",JLabel.CENTER ;label.setFont new Font "TimesRoman",Font.BOLD,24 ;label.setForeground Color.red ;基本信息 new Hashtable ;录入.addActionListener this ;修改.addActionListener this ;查询.addActionListener this ;删除.addActionListener this ;card new CardLayout ;con getContentPane ;pCenter new JPanel ;pCenter.setLayout card ;file new File "基本信息.txt" ;if !file.existstryFileOutputStream out new FileOutputStream file ;ObjectOutputStream objectOut new ObjectOutputStream out ;objectOut.writeObject 基本信息 ;objectOut.close ;out.close ;catch IOException e基本信息录入 new StudentSituation file ;基本信息修改 new ModifySituation file ;基本信息查询 new Inquest this,file ;基本信息删除 new Delete file ;pCenter.add "欢迎语界面",label ;pCenter.add "录入界面",基本信息录入 ;pCenter.add "修改界面",基本信息修改 ;pCenter.add "删除界面",基本信息删除 ;con.add pCenter,BorderLayout.CENTER ;con.validate ;addWindowListener new WindowAdapterpublic void windowClosing WindowEvent e System.exit 0 ;;setVisible true ;setBounds 100,50,420,380 ;validate ;public void actionPerformed ActionEvent e if e.getSource 录入card.show pCenter,"录入界面" ;else if e.getSource 修改card.show pCenter,"修改界面" ;else if e.getSource 查询基本信息查询.setVisible true ;else if e.getSource 删除card.show pCenter,"删除界面" ;public static void main String args[]new StudentManager ;package 学籍管理系统;/** To change this template, choose Tools | Templates* and open the template in the editor.*//**** @author Administrator*/import java.awt.*;import t.*;import javax.swing.*;import java.io.*;import java.util.*;public class StudentSituation extends JPanel implements ActionListener/****/private static final long serialVersionUID 1L;Hashtable String, Student 基本信息表 null; JTextField 学号,姓名,专业,年级,出生;JRadioButton 男,女;Student 学生 null;ButtonGroup group null;JButton 录入,重置;FileInputStream inOne null;ObjectInputStream inTwo null;FileOutputStream outOne null;ObjectOutputStream outTwo null;File file null;public StudentSituation File filethis.file file;学号 new JTextField 10 ;姓名 new JTextField 10 ;专业 new JTextField 10 ;年级 new JTextField 10 ;出生 new JTextField 10 ;group new ButtonGroup ;男 new JRadioButton "男",true ;女 new JRadioButton "女",false ;group.add 男 ;group.add 女 ;录入 new JButton "录入" ;重置 new JButton "重置" ;录入.addActionListener this ;重置.addActionListener this ;Box box1 Box.createHorizontalBox ; box1.add new JLabel "学号:",JLabel.CENTER ;box1.add 学号 ;Box box2 Box.createHorizontalBox ; box2.add new JLabel "姓名:",JLabel.CENTER ;box2.add 姓名 ;Box box3 Box.createHorizontalBox ; box3.add new JLabel "性别:",JLabel.CENTER ;box3.add 男 ;box3.add 女 ;Box box4 Box.createHorizontalBox ;box4.add new JLabel "专业:",JLabel.CENTER ;box4.add 专业 ;Box box5 Box.createHorizontalBox ; box5.add new JLabel "年级:",JLabel.CENTER ;box5.add 年级 ;Box box6 Box.createHorizontalBox ; box6.add new JLabel "出生:",JLabel.CENTER ;box6.add 出生 ;Box boxH Box.createVerticalBox ; boxH.add box1 ;boxH.add box2 ;boxH.add box3 ;boxH.add box4 ;boxH.add box5 ;boxH.add box6 ;boxH.add Box.createVerticalGlue ;JPanel pCenter new JPanel ;pCenter.add boxH ;setLayout new BorderLayout ;add pCenter,BorderLayout.CENTER ;JPanel pSouth new JPanel ;pSouth.add 录入 ;pSouth.add 重置 ;add pSouth,BorderLayout.SOUTH ;validate ;public void actionPerformed ActionEvent eif e.getSource 录入String number "";number 学号.getText ;if number.length 0tryinOne new FileInputStream file ;inTwo new ObjectInputStream inOne ;基本信息表Hashtable String, Student inTwo.readObject ;inOne.close ;inTwo.close ;catch Exception eeif 基本信息表.containsKey numberString warning "该生基本信息已存在,请到修改页面修改!";JOptionPane.showMessageDialog this,warning,"警告",JOptionPane.WARNING_MESSAGE ;elseString m "基本信息将被录入!";int ok JOptionPane.showConfirmDialog this,m,"确认",JOptionPane.YES_NO_OPTION,RMATION_MESSAGE ;if ok JOptionPane.YES_OPTIONString name 姓名.getText ;String discipling 专业.getText ;String grade 年级.getText ;String borth 出生.getText ;String sex null;if 男.isSelectedsex 男.getText ;elsesex 女.getText ;学生 new Student ;学生.setNumber number ;学生.setName name ;学生.setDiscipling discipling ;学生.setGrade grade ;学生.setBorth borth ;学生.setSex sex ;tryoutOne new FileOutputStream file ;outTwo new ObjectOutputStream outOne ;基本信息表.put number,学生 ;outTwo.writeObject 基本信息表 ;outTwo.close ;outOne.close ;学号.setText null ;姓名.setText null ;专业.setText null ;年级.setText null ;出生.setText null ;catch Exception eeSytln ee ;elseString warning "必须要输入学号!";JOptionPane.showMessageDialog this,warning,"警告",JOptionPane.WARNING_MESSAGE ;if e.getSource 重置学号.setText null ; 姓名.setText null ; 专业.setText null ; 年级.setText null ; 出生.setText null ;。
java(swing)+mysql实现学生信息管理系统源码
java(swing)+mysql实现学⽣信息管理系统源码本⽂实例为⼤家分享了java实现学⽣信息管理系统源码,供⼤家参考,具体内容如下import java.awt.BorderLayout;import java.awt.Color;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import java.util.List;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextArea;import javax.swing.table.AbstractTableModel;import javax.swing.text.BadLocationException;/*DROP DATABASE IF EXISTS `myproject`;CREATE DATABASE myproject DEFAULT CHARSET utf8 COLLATE utf8_general_ci;USE ABC;SET NAMES utf8mb4;SET FOREIGN_KEY_CHECKS = 0;DROP TABLE IF EXISTS `student`;CREATE TABLE `student` (`id` varchar(36) NOT NULL,`name` varchar(36) NOT NULL,`age` varchar(36) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;SET FOREIGN_KEY_CHECKS = 1;***/public class Test extends JFrame {private static final long serialVersionUID = 1L;private JTable table;private JPanel panel;private JScrollPane scrollpane;private JButton button1, button2, button3;private JTextArea text1, text2, text3;private List<Student> stu;public Test() throws BadLocationException, SQLException {super("学⽣信息");this.setSize(500, 340);this.add(getJScrollPane(stu), BorderLayout.CENTER);this.add(getJPanel(), BorderLayout.SOUTH);this.setResizable(true);this.setLocation(300, 300);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}// 设置JScrollPane⽅法private JScrollPane getJScrollPane(List<Student> stu) throws SQLException {if (scrollpane == null) {scrollpane = new JScrollPane();scrollpane.setViewportView(getJTable(stu));}return scrollpane;}// 设置JPanel⽅法private JPanel getJPanel() {if (panel == null) {panel = new JPanel();panel.setLayout(new GridLayout(2, 3));text1 = new JTextArea();text2 = new JTextArea();text3 = new JTextArea();button1 = new JButton("添加");button2 = new JButton("删除");button3 = new JButton("更新");button1.addActionListener(new insert());button2.addActionListener(new delete());button3.addActionListener(new update());text1.setBorder(BorderFactory.createLineBorder(Color.gray, 2));text2.setBorder(BorderFactory.createLineBorder(Color.gray, 2));text3.setBorder(BorderFactory.createLineBorder(Color.gray, 2));text1.setFont(new Font("宋体", Font.BOLD, 16));text2.setFont(new Font("宋体", Font.BOLD, 16));text3.setFont(new Font("宋体", Font.BOLD, 16));text1.setText("id");text2.setText("name");text3.setText("age");panel.add(text1);panel.add(text2);panel.add(text3);panel.add(button1);panel.add(button2);panel.add(button3);}return panel;}// 设置Jtable⽅法private void setJTable(JTable table) {table.setFont(new Font("宋体", Font.BOLD, 18));table.setRowHeight(30);}// 获取Jtable对象⽅法(该⽅法具体就是获得jtable对象的时候⼀并从数据取出学⽣信息并放⼊Jtable表格中)private JTable getJTable(List<Student> stu) throws SQLException {if (table == null) {JDBCDaoImpl jdbc = new JDBCDaoImpl();ResultSet rs = jdbc.search();stu = select(rs);jdbc.closeConnection();table = new JTable(new Table(stu));setJTable(table);}return table;}// 设置学⽣信息⽅法(该⽅法是⽤户增加删除更新⽤户操作的具体实现⽅法包含了完整性检查)private Student setStu() {if (text1.getText().equals("") || text2.getText().equals("") || text3.getText().equals("")) {return null;} else {Student sd = new Student();sd.setId(text1.getText());sd.setName(text2.getText());sd.setAge(text3.getText());return sd;}}// 重置输⼊框为空private void resetText() {text1.setText("");text2.setText("");text3.setText("");}// 刷新学⽣信息⽅法(该⽅法是重新读取数据库学⽣的信息然后返回⼀个学⽣的集合⽤于刷新Jtable表格对象中的数据) private List<Student> select(ResultSet rs) throws SQLException {List<Student> st = new ArrayList<Student>();while (rs.next()) {Student s = new Student();s.setId(rs.getString(1));s.setName(rs.getString(2));s.setAge(rs.getString(3));st.add(s);}return st;}// 添加按钮-监听器(该⽅法是对添加按钮实现的具体⽅法)class insert implements ActionListener {@Overridepublic void actionPerformed(ActionEvent e) {stu = new ArrayList<Student>();Student sd = new Student();JDBCDaoImpl jdbc = new JDBCDaoImpl();sd = setStu();if (sd != null) {jdbc.insert(sd);ResultSet rs = jdbc.search();try {stu = select(rs);} catch (SQLException e1) {e1.printStackTrace();}jdbc.closeConnection();JTable table = new JTable(new Table(stu));//新建⼀个Jtable 对象⽤来盛放增加后的学⽣信息 setJTable(table);//设置Jtable信息Test.this.scrollpane.setViewportView(table);//把Jtable设置到PanelresetText();} else {JOptionPane.showMessageDialog(Test.this, "输⼊数据不完整");}}}// 删除按钮-监听器(该⽅法是对删除按钮实现的具体⽅法)class delete implements ActionListener {@Overridepublic void actionPerformed(ActionEvent e) {stu = new ArrayList<Student>();Student sd = new Student();JDBCDaoImpl jdbc = new JDBCDaoImpl();sd = setStu();if (sd != null) {jdbc.delete(sd);ResultSet rs = jdbc.search();try {stu = select(rs);} catch (SQLException e1) {e1.printStackTrace();}jdbc.closeConnection();JTable table = new JTable(new Table(stu));//新建⼀个Jtable 对象⽤来盛放增加后的学⽣信息 setJTable(table);//设置Jtable信息Test.this.scrollpane.setViewportView(table);//把Jtable设置到PanelresetText();} else {JOptionPane.showMessageDialog(Test.this, "输⼊数据不完整");}}}// 更新按钮-监听器(该⽅法是对更新按钮实现的具体⽅法)class update implements ActionListener {@Overridepublic void actionPerformed(ActionEvent e) {stu = new ArrayList<Student>();Student sd = new Student();JDBCDaoImpl jdbc = new JDBCDaoImpl();sd = setStu();if (sd != null) {jdbc.update(sd);ResultSet rs = jdbc.search();try {stu = select(rs);} catch (SQLException e1) {e1.printStackTrace();}jdbc.closeConnection();JTable table = new JTable(new Table(stu));//新建⼀个Jtable 对象⽤来盛放增加后的学⽣信息setJTable(table);//设置Jtable信息Test.this.scrollpane.setViewportView(table);//把Jtable设置到PanelresetText();} else {JOptionPane.showMessageDialog(Test.this, "输⼊数据不完整");}}}// Student类(⽤于封装数据信息和数据库表进⾏映射)public class Student {// 学⽣的id name age信息private String id;private String name;private String age;// get&set⽅法public String getId() {return id;}public void setId(String id) {this.id = id;}public String getName() {return name;}public void setName(String name) { = name;}public String getAge() {return age;}public void setAge(String age) {this.age = age;}}// JTable 表模式类(JTable对象初始化的时候通过这个Table获取表格的⾏数、列数、列标题、以及每个单元格存放的数据具体使⽤原因放在开头的备注了) public class Table extends AbstractTableModel {List<Student> stu = new ArrayList<Student>();public Table(List s) {this.stu = s;}public List<Student> getStu() {return stu;}public void setStu(List<Student> stu) {this.stu = stu;}@Override// 获取⾏数public int getRowCount() {return stu.size();}@Override// 获取列数public int getColumnCount() {// TODO Auto-generated method stubreturn 3;}@Overridepublic boolean isCellEditable(int rowIndex, int columnIndex) {return true;}@Override// 获取列名字public String getColumnName(int col) {String res = "";switch (col) {case 0:res = "ID";break;case 1:res = "Name";break;case 2:res = "Age";break;default:break;}return res;}@Override// 获取具体值public Object getValueAt(int rowIndex, int columnIndex) {// TODO Auto-generated method stubObject res = "";Student temp = stu.get(rowIndex);switch (columnIndex) {case 0:res = temp.getId();break;case 1:res = temp.getName();break;case 2:res = temp.getAge();break;default:break;}return res;}}// JDBCDAO类配置连接数据的信息,链接释放操作和基本增删改查操作public class JDBCDaoImpl {String driver = "com.mysql.jdbc.Driver";String url = "jdbc:mysql://localhost:3306/test1?useUnicode=true&characterEncoding=utf-8&useSSL=false"; String user = "root";String passwd = "123456";Connection conn = null;Statement stmt = null;ResultSet rs = null;// 数据库连接开始public Connection getConnection() {try {Class.forName("com.mysql.jdbc.Driver");conn = DriverManager.getConnection(url, user, passwd);stmt = conn.createStatement();} catch (Exception e) {e.printStackTrace();}return conn;}// 数据库连接释放public void closeConnection() {if (rs != null) {try {rs.close();stmt.close();conn.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if (rs == null) {try {stmt.close();conn.close();} catch (SQLException e) {e.printStackTrace();}}}// 查找操作public ResultSet search() {getConnection();try {String sql = "SELECT * FROM student";rs = stmt.executeQuery(sql);} catch (SQLException e) {e.printStackTrace();}return rs;}// 添加操作public void insert(Student sd) {// TODO Auto-generated method stubgetConnection();try {String sql = "INSERT INTO student(id,name,age)" + "VALUES('" + sd.getId() + "','" + sd.getName() + "','" + sd.getAge() + "')";int count = stmt.executeUpdate(sql);} catch (SQLException e) {e.printStackTrace();}}// 删除操作public void delete(Student sd) {// TODO Auto-generated method stubgetConnection();try {String sql = "DELETE FROM student WHERE id = '" + sd.getId() + "'";int count = stmt.executeUpdate(sql);} catch (SQLException e) {e.printStackTrace();}}// 更新操作public void update(Student sd) {// TODO Auto-generated method stubgetConnection();try {String sql = "UPDATE student SET name='" + sd.getName() + "',age= '" + sd.getAge() + "'WHERE id = '" + sd.getId() + "'";int count = stmt.executeUpdate(sql);} catch (SQLException e) {e.printStackTrace();}}}// main ⽅法public static void main(String[] args) throws BadLocationException, SQLException {new Test().setVisible(true);}}关于管理系统的更多内容请点击进⾏学习以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
简单学生管理信息系统源代码
package xsgl;import java.awt。
*;import java.awt。
event。
*;import java。
sql。
*;import java。
util.*;import javax。
swing。
*;import java。
util。
Vector;import javax.swing。
table.*;import java。
awt。
event.*;public class Xsglxt extends JFrame implements ActionListener//继承JFrame 并实现接口ActionListener{JPanel mb1,mb2;JLabel bq1;JTextField wbk1;JButton an1,an2,an3,an4;JTable bg1; //定义表格对象JScrollPane gd1;Xsxx xsxx2;//定义Xsxx类的一个对象xsxx2 public static void main(String[] args){Xsglxt xs=new Xsglxt();}public Xsglxt() //XSGLXT构造方法,用于对象初始化。
{mb1=new JPanel();bq1=new JLabel(”请输入姓名”);wbk1=new JTextField(10);an1=new JButton(”查询”);an1.addActionListener(this); //对按钮1添加监听an1。
setActionCommand(”chaxun”);//设置按钮1的监听信息mb1.add(bq1);mb1.add(wbk1); mb1.add(an1);mb2=new JPanel();an2=new JButton("添加”);an2。
addActionListener(this);an2。
setActionCommand("tianjia”);an3=new JButton(”修改”);an3.addActionListener(this);an3。
Java学生信息管理系统源码
Java学⽣信息管理系统源码
学⽣信息管理系统
功能说明
学⽣信息管理,包括学⽣、班级、院系、课程、成绩等的管理。
本程序仅供学习⾷⽤。
⼯程环境
JDK
IntelliJ IDEA
MySQL
运⾏说明
1、安装JDK。
2、导⼊SQL脚本并配置。
使⽤前请导⼊DumpStructureOnly.sql(数据库结构⽂件)
或者
DumpStructure_and_Data.sql(带有测试数据的数据库⽂件),
使⽤Navicat导⼊上述脚本⾄MySQL数据库
修改dbConn.java配置⽂件:
数据库端⼝:3306
数据库名:stuManagerDB
数据库⽤户名:root
数据库密码:123456
3、运⾏程序
4、系统登录
打开本程序⾸先进⼊登录界⾯,有账号可直接登录,⽆账号点击注册进⾏注册登陆。
帐号密码可以通过数据库tb_user表查询(本源码使⽤的明码保存,⽣产项⽬密码是要加密的)
注意:注册,默认注册普通⽤户(userType = 2),普通⽤户⽆添加⽤户、删除⽤户功能;要添加管理员账号(userType = 1)必须在数据库添加。
DumpStructure_and_Data.sql数据库的tb_user表中有学⽣系统管理员账号:admin,密码为空,可以⽤其登录测试。
学生学籍管理系统源代码
学生学籍管理系统源代码源代码:连接数据库的代码:package cn.system.manage.tools; import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class DBAccess {final static private String strDriver="com.mysql.jdbc.Driver";final static private Stringurl="jdbc:mysql://localhost:3306/xjgl?userUnicode=true&characterEnco ding=gb2312";final static private String user="root";final static private String password="admin";private static DBAccess db = null;private Connection con;private Statement stmt;private ResultSet rst;private DBAccess(){try {Class.forName(strDriver);con=DriverManager.getConnection(url, user, password); stmt=con.createStatement();} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public static DBAccess getDBAccess(){if(db==null){db= new DBAccess();}return db;}public Connection getConnection(){return con;}public ResultSet query(String sql){try {rst=stmt.executeQuery(sql);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return rst;}public int update(String sql){int flag=0;try {flag=stmt.executeUpdate(sql);} catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace();return -1;}return flag;}public void close(){try {rst.close();stmt.close();con.close();} catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace();}}public ResultSet queryScroll(String sql){try{stmt = con.createStatement(1004, 1007);return stmt.executeQuery(sql);}catch(SQLException sqlexception){return null;}}}转换字符集代码:package cn.system.manage.tools;import java.io.IOException;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException; import javax.servlet.ServletRequest;import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; public class CharFilter implements Filter {public void destroy() {// TODO Auto-generated method stub}public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {// TODO Auto-generated method stubHttpServletRequest request = (HttpServletRequest)arg0;HttpServletResponse response = (HttpServletResponse)arg1;request.setCharacterEncoding("GBK");response.setCharacterEncoding("GBK");arg2.doFilter(arg0, arg1);}public void init(FilterConfig arg0) throws ServletException { // TODO Auto-generated method stub}}分页代码:package cn.system.manage.tools;import java.io.Serializable;import java.util.ArrayList;public class PageBean implements Serializable{ArrayList list;int pageNo;int pageSize;int pageSum;int rowCount;int pagePrev;int pageNext;int hasFirst;int hasPrev;int hasNext;int hasEnd;public PageBean(){list = null;list = new ArrayList();}public ArrayList getList(){return list;}public void setPageInfo(int myRowCount, int myPageSize) {if(myPageSize > 0){setPageSize(myPageSize);setRowCount(myRowCount);if(myRowCount > 0)setPageSum(((myRowCount + myPageSize) - 1) / myPageSize); }}public void setList(ArrayList list){this.list = list;}public int getPageNo(){return pageNo;}public void setPageNo(int pageNo){this.pageNo = pageNo;}public int getPagePrev(){return pageNo - 1;}public int getPageNext(){return pageNo + 1;}public int getPageSum(){return pageSum;}public void setPageSum(int pageSum) {this.pageSum = pageSum;}public int getHasPrev(){if(pageSum > 1)return pageNo >= 2 ? 1 : 0;elsereturn 0;}public int getHasNext(){if(pageSum > 1)return pageNo < pageSum ? 1 : 0; elsereturn 0;}public int getHasFirst(){if(pageSum > 1)return pageNo <= 1 ? 0 : 1;elsereturn 0;}public int getHasEnd(){if(pageSum > 1)return pageNo >= pageSum ? 0 : 1; elsereturn 0;}public int getPageSize(){return pageSize;}public void setPageSize(int pageSize) {this.pageSize = pageSize;}public void setPagePrev(int pagePrev) {this.pagePrev = pagePrev;}public void setHasPrev(int hasPrev) {this.hasPrev = hasPrev;}public void setHasNext(int hasNext) {this.hasNext = hasNext;}public void setHasFirst(int hasFirst) {this.hasFirst = hasFirst;}public void setHasEnd(int hasEnd) {this.hasEnd = hasEnd;}public void setPageNext(int pageNext) {this.pageNext = pageNext;}public int getRowCount(){return rowCount;}public void setRowCount(int rowCount) {this.rowCount = rowCount;}}。
(完整版)JAVA学生管理系统源代码
JA V A学生管理系统源代码一、程序import java.util.*;public class Test {//主程序public static void main(String[] args){Scanner in = new Scanner(System.in);System.out.println("------请定义学生的人数:------");Student[] stuArr = new Student[in.nextInt()];Admin adminStu = new Admin();while(true){System.out.println("-----请选择你要执行的功能-----");System.out.println("10:添加一个学生");System.out.println("11:查找一个学生");System.out.println("12:根据学生编号更新学生基本信息");System.out.println("13:根据学生编号删除学生");System.out.println("14:根据编号输入学生各门成绩");System.out.println("15:根据某门成绩进行排序");System.out.println("16:根据总分进行排序");System.out.println("99:退出系统");String number = in.next();if(number.equals("10")){System.out.println("请输入学生的编号:");int num = in.nextInt();System.out.println("请输入学生的姓名:");String name = in.next();System.out.println("请输入学生的年龄:");int age = in.nextInt();adminStu.Create(num,name,age,stuArr);//添加学生}else if(number.equals("11")){System.out.println("执行查找学生基本信息的操作");System.out.println("请输入学生的编号进行查找:");int num = in.nextInt();adminStu.find(num,stuArr);//查找学生}else if(number.equals("12")){System.out.println("执行更新学员的基本信息操作");System.out.println("请输入学生的编号:");int num = in.nextInt();System.out.println("请输入学生的姓名:");String name = in.next();System.out.println("请输入学生的年龄:");int age = in.nextInt();adminStu.update(num,name,age,stuArr);//更新学生基本信息}else if(number.equals("13")){System.out.println("执行删除学生操作");System.out.println("请输入学生编号:");int num = in.nextInt();adminStu.delete(num,stuArr);//删除学生}else if(number.equals("14")){System.out.println("执行输入成绩操作");System.out.println("请输入学生编号:");int num = in.nextInt();adminStu.input(num, stuArr);//输入成绩}else if(number.equals("15")){System.out.println("执行根据某科目成绩排序操作");System.out.println("请选择需要排序的科目名(1.java 2.C# 3.html 4.sql):");int num = in.nextInt();adminStu.courseSort(num,stuArr);//按科目排序}else if(number.equals("16")){System.out.println("执行根据总分排序操作");adminStu.sumSort(stuArr);//按总分排序}else if(number.equals("99")){System.out.println("--------程序已退出--------");//break;System.exit(0);}}}}二、学生类public class Student {//学生类private int num;private String name;private int age;private int java;private int C;private int html;private int sql;private int sum;private int avg;public int getNum() {return num;}public void setNum(int num) { this.num = num;}public String getName() {return name;}public void setName(String name) { = name;}public int getAge() {return age;}public void setAge(int age) { this.age = age;}public int getJava() {return java;}public void setJava(int java) { this.java = java;}public int getC() {return C;}public void setC(int c) {C = c;}public int getHtml() {return html;}public void setHtml(int html) { this.html = html;}public int getSql() {return sql;}public void setSql(int sql) { this.sql = sql;}public int getSum() {return sum;}public void setSum() {this.sum = this.java+this.C+this.html+this.sql;}public int getAvg() {return avg;}public void setAvg() {this.avg = this.sum/4;}public String toString(){String str= "\t"+this.num+"\t"++"\t"+this.age+"\t"+this.java+"\t"+this.C+"\t"+this.html+"\t"+this.sql+"\t"+this.sum+"\t"+this.avg;return str;}}三、管理学生类import java.util.*;public class Admin {//用来管理学生的一个类String msg = "\t编号\t姓名\t年龄\tjava\tC#\thtml\tsql\t总分\t 平均分";public void print(Student[] arr){//刷新数据的方法System.out.println(msg);for(int i=0;i<arr.length;i++){if(arr[i]!=null){arr[i].setSum();arr[i].setAvg();System.out.println(arr[i]);}}}public boolean exist(int num,Student stu){//判断学生是否存在的方法if(stu!=null){if(stu.getNum()==num){return true;}else{return false;}}return false;}public void Create(int num,String name,int age,Student[] arr){//添加学生的方法Student stu = new Student();stu.setNum(num);stu.setName(name);stu.setAge(age);int i = this.setIndex(arr);if(i==99999){System.out.println("学生人数已添满,不能再添加了");}else{arr[i]=stu;}this.print(arr);}public int setIndex(Student[] arr){//返回数组为空的下标for(int i=0;i<arr.length;i++){if(arr[i]==null){return i;}}return 99999;}public void find(int num,Student[] arr){//查询学生的方法for(int i=0;i<arr.length;i++){//判断学生是否存在if(this.exist(num,arr[i])==true){System.out.println(msg);System.out.println(arr[i]);return;}}System.out.println("-----没有这个学生的存在-----");}public void update(int num,String name,int age,Student[] arr){//更新学生基本信息的方法for(int i=0;i<arr.length;i++){if(this.exist(num, arr[i])==true){arr[i].setName(name);arr[i].setAge(age);System.out.println("--------更新学生信息成功!-------");this.print(arr);return;}}System.out.println("------没找到这个学生更新信息失败------");}public void delete(int num,Student[] arr){//删除学生的方法for(int i=0;i<arr.length;i++){if(this.exist(num,arr[i])){arr[i] = null;this.print(arr);return;}}System.out.println("您所指定编号的学生不存在");}public void input(int num,Student[] arr){//输入学生成绩的方法for(int i=0;i<arr.length;i++){if(this.exist(num, arr[i])){Scanner in = new Scanner(System.in);System.out.println("请输入"+arr[i].getName()+"java 的成绩:");if(in.hasNextInt()){//输入非整形数则不执行arr[i].setJava(in.nextInt());}else{return;}System.out.println("请输入"+arr[i].getName()+"C#的成绩:");if(in.hasNextInt()){arr[i].setC(in.nextInt());}else{return;}System.out.println("请输入"+arr[i].getName()+"html 的成绩:");if(in.hasNextInt()){arr[i].setHtml(in.nextInt());}else{return;}System.out.println("请输入"+arr[i].getName()+"sql 的成绩:");if(in.hasNextInt()){arr[i].setSql(in.nextInt());}else{return;}this.print(arr);return;}}}public void courseSort(int num,Student[] arr){//根据指定科目排序的方法if(num==1){//这里不能用冒泡排序(因为冒泡排序是相邻的比较,而相邻的可能不存在,那么相隔的两个就不能交换)for(int i=0;i<arr.length;i++){for(int j=i+1;j<arr.length;j++){if(arr[i]!=null&&arr[j]!=null){if(arr[i].getJava()<arr[j].getJava()){Student t = arr[i];arr[i] = arr[j];arr[j] = t;}}}}}else if(num==2){for(int i=0;i<arr.length;i++){for(int j=i+1;j<arr.length;j++){if(arr[i]!=null&&arr[j]!=null){if(arr[i].getC()<arr[j].getC()){Student t = arr[i];arr[i] = arr[j];arr[j] = t;}}}}}else if(num==3){for(int i=0;i<arr.length;i++){for(int j=i+1;j<arr.length;j++){if(arr[i]!=null&&arr[j]!=null){if(arr[i].getHtml()<arr[j].getHtml()){Student t = arr[i];arr[i] = arr[j];arr[j] = t;}}}}}else if(num==4){for(int i=0;i<arr.length;i++){for(int j=i+1;j<arr.length;j++){if(arr[i]!=null&&arr[j]!=null){if(arr[i].getSql()<arr[j].getSql()){Student t = arr[i];arr[i] = arr[j];arr[j] = t;}}}}}this.print(arr);}public void sumSort(Student[] arr){//根据总分排序的方法for(int i=0;i<arr.length;i++){for(int j=i+1;j<arr.length;j++){if(arr[i]!=null&&arr[j]!=null){if(arr[i].getSum()<arr[j].getSum()){Student t = arr[i];arr[i] = arr[j];arr[j] = t;}}}}this.print(arr);}}。
JAVA项目源码 数据库创建 学生信息管理系统
create data base JavaTestgouse JavaTestgocreate table登陆(用户名char(20)primary key,密码char(20))goinsert into登陆values('Administrator','111')insert into登陆values('111','111')gocreate table学生信息(学号varchar(15)primary key,姓名varchar(10)not null,性别char(4)not null,年龄int not null,宿舍varchar(20)not null,家庭住址varchar(50)not null)goinsert into学生信息values('20061052541','王鹏','男',20,'11#A104','河南省郑州市');insert into学生信息values('20061052542','黎明','男',20,'11#A104','河南省郑州市');insert into学生信息values('20061052543','小妮','女',21,'8#A104','北京市');insert into学生信息values('20061052544','黎明','男',20,'11#A104','河南省郑州市');insert into学生信息values('20061052545','黎明','男',20,'11#A104','河南省郑州市'); create table学生信息删除历史(学号varchar(15),姓名varchar(10),性别char(4),年龄int,宿舍varchar(20),家庭住址varchar(50))goinsert into学生信息删除历史values('20061052545','张三','男',20,'11#A104','河南省郑州市'); insert into学生信息values('20061052545','黎明','男',20,'11#A104','河南省郑州市');gocreate trigger删除历史到新表on学生信息after deleteasbeginprint'开始添加删除的数据到新表'insert into学生信息删除历史select*from deletedprint'完成添加删除的数据到新表' endgo。
学生信息管理平台源代码(JAVA 版)
JAVA课程设计学生信息管理系统代码
JAVA课程设计学生信息管理系统代码某Tochangethitemplate,chooeTool|Template某andopenthetemplateintheeditor.某/packagetudentinfo;importjava.awt.某;importjava某.wing.某;importjava.awt.event.某;importjava.awt.某;importjava.awt.event.某;importjava.util.某;importjava某.wing.border.某;importjava某.wing.JOptionPane;importjava某.wing.JLabel;importjava某.wing.JPanel;importjava某.wing.table.DefaultTableModel; importjava某.wing.table.TableColumn;importjava.ql.某;importjava.awt.GridLayout;//网格式布局//导入javar需要的jar包publicclaStudentInfo{publicStudentInfo()//构造方法{}publictaticvoidmain(String[]arg){//TODOcodeapplicationlogichereloginFramelf=newloginFrame();//加载窗体lf.etViible(true);//设置窗体可见lf.addWindowLitener(newWindowAdapter()//添加窗口监听以接受关闭事件{publicvoidwindowCloing(WindowEvente){Sytem.e某it(0);}});}}//学生成绩管理系统界面clamainFramee某tendJFrameimplementActionLitener{MenuBarmyMenuBar=newMenuBar();//菜单MenuItemmiNew,miOpen,miSave,miSaveA,miE某it;MenuItemmiAdd,miEdit,miDel,miFind,miShow,miUer,miAbout;public JTabletable=newJTable();//表格publicDefaultTableModelmm;//表格模型publicmainFrame(){myMenuFile=newMenu("文件");miNew=newMenuItem("新建");miOpen=newMenuItem("打开");miSave=newMenuItem("保存");miE某it=newMenuItem("退出");//miNew.enable(fale);//miOpen.enable(fale);//miSave.enable(fa le);//myMenuFile.add(miNew);//myMenuFile.add(miOpen);//myMenuFil e.add(miSave);myMenuFile.add(miE某it);myMenuEdit=newMenu("数据编辑");miFind=newMenuItem("查找数据");miAdd=newMenuItem("添加数据");miEdit=newMenuItem("修改数据");miDel=newMenuItem("删除数据");miShow=newMenuItem("全部显示");myMenuEdit.add(miFind);myMenuEdit.add(miAdd);myMenuEdit.add(m iEdit);myMenuEdit.add(miDel);myMenuEdit.add(miShow);myMenuUer=ne wMenu("用户管理");miUer=newMenuItem("编辑用户");myMenuUer.add(miUer);myMenuAbout=newMenu("关于我");miAbout=newMenuItem("我的信息");myMenuAbout.add(miAbout);myMenuBar.add(myMenuFile);myMenuBar.add(myMenuEdit);myMenuBar.add(myMenuUer);myMenuBar.add(myMenuAbout);String[]col={"学号","姓名","性别","班级","专业","大学语文","大学英语","高等数学"};//创建属性列名table.etModel(mm);JScrollPanetableScrollPane=newJScrollPane( table);//设置滚动条thi.etMenuBar(myMenuBar);thi.add(tableScrollPane);miE某it.addActionLitener(thi);//为各按钮注册事件监听器对象miFind.addActionLitener(thi);miAdd.addActionLitener(thi);miEdit. addActionLitener(thi);miDel.addActionLitener(thi);miShow.addActi onLitener(thi);miUer.addActionLitener(thi);miAbout.addActionLite ner(thi);}publicvoidfrehTable(Stringql){myConnectionconn=newmyCo nnection();//获得数据库连接ReultSetr;//保存查询返回结果对象r=conn.getReult(ql);if(r!=null){try{mm.etRowCount(0);table.etMod el(mm);while(r.ne某t()){String学号=r.getString("学号");String姓名=r.getString("姓名");String性别=r.getString("性别");String班级=r.getString("班级");String专业=r.getString("专业");String大学语文=r.getString("大学语文");String大学英语=r.getString("大学英语");String高等数学=r.getString("高等数学");String[]cloumn={学号,姓名,性别,班级,专业,大学语文,大学英语,高等数学};mm.addRow(cloumn);}//table.clearSelection();table.etModel(mm );}catch(E某ceptione){}}}//捕获异常publicvoidactionPerformed(ActionEvente)//重载动作事件接口中的方法{//退出if(e.getSource()==miE某it){Sytem.e 某it(0);//查找}eleif(e.getSource()==miFind){findFrameff=newfindFrame(thi);ff .etViible(true);//添加}eleif(e.getSource()==miAdd){addFrameaf=newaddFrame(thi);af.et Viible(true);//修改}eleif(e.getSource()==miEdit){if(table.getSelectedRow()==-1){JOptionPane.howMeageDialog(null,"请选择你要修改的内容","温馨提示",RMATION_MESSAGE);//弹窗提示}{editFrameef=neweditFrame(thi);ef.学号.etTe某t((String)table.getValueAt(table.getSelectedRow(),0));ef.姓名.etTe某t((String)table.getValueAt(table.getSelectedRow(),1));ef.性别.etTe某t((String)table.getValueAt(table.getSelectedRow(),2));ef.班级.etTe某t((String)table.getValueAt(table.getSelectedRow(),3));ef.专业.etTe某t((String)table.getValueAt(table.getSelectedRow(),4));ef.大学语文.etTe某t((String)table.getValueAt(table.getSelectedRow(),5));ef.大学英语.etTe某t((String)table.getValueAt(table.getSelectedRow(),6));ef.高等数学.etTe某t((String)table.getValueAt(table.getSelectedRow(),7));ef.etViibl e(true);thi.frehTable("elect某from学生成绩表");//刷新表格}//删除eleif(e.getSource()==miDel){if(table.getSelectedRow()==-1){JOptionPane.howMeageDialog(null,"请选择你要删除的行","温馨提示",RMATION_MESSAGE);}ele{Stringql="deletefrom学生成绩表where学号='"+table.getValueAt(table.getSelectedRow(),0)+"'";//JOptionPane.howMeageDialog(null,ql,"温馨提示",RMATION_MESSAGE);myConnectionconn=newmyConnection();if(conn.e某ecuteSql(ql)){JOptionPane.howMeageDialog(null,"成功删除","温馨提示",RMATION_MESSAGE);thi.frehTable("elect某from学生成绩表");ele{JOptionPane.howMeageDialog(null,"未知错误","删除失败",RMATION_MESSAGE);}}//显示}eleif(e.getSource()==miShow){//JOptionPane.howMeageDialog(null,"未知错误","删除失败",RMATION_MESSAGE);thi.frehTable("elect某from学生成绩表");//编辑用户}eleif(e.getSource()==miUer){uerFrameuf=newuerFrame();uf.etViible(true);//作业说明}eleif(e.getSource()==miAbout){aboutFrameaf=newaboutFrame();af.etViible(true);}}}clamyConnection{ReultSetre;Stringtrurl="jdbc:odbc:driver={MicrooftAcceDriver(某.mdb)};D BQ=学生管理数据库.mdb";//Stringtrurl="jdbc:odbc:driver={MicrooftAcceDriver(某.mdb)} ;DBQ=学生管理数据库.mdb";//Stringtrurl="jdbc:odbc:cah";//cah为数据源名称publicmyConnection(){}publicReultSetgetReult(Stringql){try{Cla.forName("un.jdbc.odbc.JdbcOdbcDriver");Connectionconn=DriverManager.getConnection(trurl);Statementtmt=conn.createStatement(ReultSet.TYPE_SCROLL_SENSITIVE,Reul tSet.CONCUR_UPDATABLE);ReultSetre=tmt.e某ecuteQuery(ql);returnre;}catch(E某ceptione){e.printStackTrace();//异常处理returnnull;}}publicbooleane某ecuteSql(Stringql){try{Cla.forName("un.jdbc.odbc.JdbcOdbcDriver"); Connectionconn=DriverManager.getConnection(trurl); Statementtmt=conn.createStatement();tmt.e某ecuteUpdate(ql);mit();returntrue;}catch(E某ceptione){e.printStackTrace();returnfale;}}}claaddFramee某tendJDialogimplementActionLitener {publictaticfinalintWIDTH=400;publictaticfinalintHEIGHT=400;JLabel学号1,姓名1,性别1,班级1,专业1,大学语文1,大学英语1,高等数学1;JTe某tField学号,姓名,性别,班级,专业,大学语文,大学英语,高等数学;JButtonb;JPanelp;mainFramemf;publicaddFrame(mainFramemmf){etT itle("添加学生成绩");etSize(WIDTH,HEIGHT);etLocation(120,180);ContainercontentPane =getContentPane();//创建一个容器对象contentPane.etLayout(newFlowLayout());//流式布局学号1=newJLabel("学号");姓名1=newJLabel("姓名");性别1=newJLabel("性别");班级1=newJLabel("班级");专业1=newJLabel("专业");大学语文1=newJLabel("大学语文");大学英语1=newJLabel("大学英语");高等数学1=newJLabel("高等数学");学号=newJTe某tField(5);姓名=newJTe某tField(5);性别=newJTe某tField(5);班级=newJTe某tField(5);专业=newJTe某tField(5);大学语文=newJTe某tField(5);大学英语=newJTe 某tField(10);高等数学=newJTe某tField(10);b=newJButton("确定");p=newJPanel();p.etLayout(newGridLayout(10,2,5,5));//表格布局p.add(学号1);p.add(学号);p.add(姓名1);p.add(姓名);p.add(性别1);p.add(性别);p.add(班级1);p.add(班级);p.add(专业1);p.add(专业);p.add(大学语文1);p.add(大学语文);p.add(大学英语1);p.add(大学英语);p.add(高等数学1);p.add(高等数学);p.add(newLabel(""));p.add(newLabel(""));p.add(b);contentPane .add(p);//添加按钮监听器b.addActionLitener(thi);mf=mmf;}publicvoidactionPerformed(ActionEvente){if(学号.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入学号","温馨提示",RMATION_MESSAGE);}eleif(姓名.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入姓名","温馨提示",RMATION_MESSAGE);}eleif(大学语文.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入大学语文","温馨提示",RMATION_MESSAGE);}ele{Stringql="elect某from学生成绩表where学号='"+学号.getTe某t()+"'";myConnectionconn=newmyConnection();ReultSetr;r=conn.getReult (ql);try{//Sytem.out.println(r.getRow());if(r.ne某t()){ JOptionPane.howMeageDialog(null,"此学号已经存在","温馨提示",RMATION_MESSAGE);误信息}//添加学生的时候,发现数据库已经有了,提示你学号已经存在,报错ele{ql="inertinto学生成绩表value('"+学号.getTe某t()+"','"+姓名.getTe某t()+"','"+性别.getTe某t()+"','"+班级.getTe某t()+"','"+专业.getTe某t()+"','"+大学语文.getTe某t()+"','"+大学英语.getTe某t()+"','"+高等数学.getTe某t()+"')";//实行数据库插入的语句if(conn.e某ecuteSql(ql))//插入语句{JOptionPane.howMeageDialog(null,"添加成功","温馨提示",RMATION_MESSAGE);}ele{mf.frehTable("elect某from学生成绩表");学号.etTe某t("");姓名.etTe某t("");性别.etTe某t("");班级.etTe某t("");专业.etTe某t("");大学语文.etTe某t("");大学英语.etTe某t("");高等数学.etTe某t("");JOptionPane.howMeageDialog(null,"添加失败","温馨提示",RMATION_MESSAGE);}//插入失败}}catch(E某ceptioner){Sytem.out.println(er.toString());}}}}claeditFramee某tendJDialogimplementActionLitener{publictaticfinalintWIDTH=400;publictaticfinalintHEIGHT=400;JLabel学号1,姓名1,性别1,班级1,专业1,大学语文1,大学英语1,高等数学1;JTe某tField学号,姓名,性别,班级,专业,大学语文,大学英语,高等数学;JButtonb;JPanelp;mainFramemf;publiceditFrame(mainFramemmf){et Title("修改学生信息");etSize(WIDTH,HEIGHT);etLocation(120,180);ContainercontentPane =getContentPane();contentPane.etLayout(newFlowLayout());学号1=newJLabel("学号");姓名1=newJLabel("姓名");性别1=newJLabel("性别");班级1=newJLabel("班级");专业1=newJLabel("专业");大学语文1=newJLabel("大学语文");大学英语1=newJLabel("大学英语");高等数学1=newJLabel("高等数学");学号=newJTe某tField(5);姓名=newJTe某tField(5);性别=newJTe某tField(5);班级=newJTe某tField(5);专业=newJTe某tField(5);大学语文=newJTe某tField(5);大学英语=newJTe 某tField(10);高等数学=newJTe某tField(10);学号.etEnabled(fale);b=newJButton("确定");p=newJPanel();p.etLayout(newGridLayout(10,2,5,5));p.add(学号1);p.add(学号);p.add(姓名1);p.add(姓名);p.add(性别);p.add(班级1);p.add(班级);p.add(专业1);p.add(专业);p.add(大学语文1);p.add(大学语文);p.add(大学英语1);p.add(大学英语);p.add(高等数学1);p.add(高等数学);p.add(newLabel(""));p.add(newLabel(""));p.add(b);contentPane .add(p);//添加按钮监听器b.addActionLitener(thi);mf=mmf;}//这是画界面publicvoidactionPerformed(ActionEvente){if(学号.getTe某t().toString().equal(""))//判断{JOptionPane.howMeageDialog(null,"请输入学号","温馨提示",RMATION_MESSAGE);//弹出的小窗口提示}eleif(姓名.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入姓名","温馨提示",RMATION_MESSAGE);}eleif(大学语文.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入大学语文","温馨提示",RMATION_MESSAGE);}ele{Stringql="update学生成绩表et姓名='"+姓名.getTe某t()+"',性别='"+性别.getTe某t()+"',班级='"+班级.getTe某t()+"',专业='"+专业.getTe某t()+"',大学语文='"+大学语文.getTe某t()+"',大学英语='"+大学英语.getTe某t()+"',高等数学='"+高等数学.getTe某t()+"'where学号='"+学号.getTe某t()+"'";myConnectionconn=newmyConnection();//打开数据库的连接try{//JOptionPane.howMeageDialog(null,ql,"温馨提示",RMATION_MESSAGE);if(conn.e某ecuteSql(ql))//执行ql语句,弹出窗口,查询学生表刷新table{JOptionPane.howMeageDialog(null,"修改成功","温馨提示",RMATION_MESSAGE);mf.frehTable("elect某from学生成绩表");thi.dipoe();//关闭当前窗体对象,隐藏}ele{JOptionPane.howMeageDialog(null,"修改失败","温馨提示",RMATION_MESSAGE);}}catch(E某ceptioner){er.printStackTrace();}}}}clafindFramee某tendJDialogimplementActionLitener{mainFramemf;JPanelp;JTe某tFieldt;JButtonb;JButtonfAll;Stringql="elect某fromtudent";String[]colStr={"学号","姓名","性别","班级","专业","大学语文","大学英语","高等数学"};publicfindFrame(mainFramemmf) {mf=mmf;p=newJPanel();t=newJTe某tField(10);b=newJButton("查找");fAll=newJButton("全部显示");b.addActionLitener(thi);fAll.addActionLitener(thi);p.add(newJLabel("选择"));p.add(c);p.add(newJLabel("查找内容"));p.add(t);p.add(b);p.add(fAll);thi.add(p);thi.etTitle("查找");thi.etSize(450,80);}publicvoidactionPerformed(ActionEvente){//查找if(e.getSource()==b){StringelectStr=c.getSelectedItem().toString(); if(electStr=="大学英语"){ql="elect某from学生成绩表"+t.getTe某t().toString();}ele{ql="elect某from学生成绩表'"+t.getTe某t().toString()+"'";}mf.frehTable(ql);//全部显示}if(e.getSource()==fAll){ql="elect某from学生成绩表";mf.frehTable(ql);}//监听程序,选择查成绩,最后是重新刷新table }}claaboutFramee某tendJDialog//关于我的信息{aboutFrame(){JPanelp1=newJPanel();where"+electStr+"where"+electStr+"== clauerFramee某tendJFrameimplementActionLitener//用户密码{JTe某tFielduer,pa;JButtonadd,del;JTablet;JPanelp1,p2,p3,p4,p5;DefaultTableModelm;publicuerFrame(){p1=newJPanel();p2=newJPanel();p3=newJPanel();p4=newJPanel();p5=newJPanel();uer=newJTe某tField(8);pa=newJTe某tField(8);add=newJButton("添加");del=newJButton("删除");String[]col={"用户名","密码"};m=newDefaultTableModel(col,0);t=newJTable();t.etModel(m);JScr ollPanep=newJScrollPane(t);p1.add(newJLabel("用户名"));p1.add(uer);p1.add(newJLabel("密码"));p1.add(pa);p1.add(add);p2.add(p);p3.add(del);add.addActionLi tener(thi);del.addActionLitener(thi);myConnectionconn=newmyConne ction();ReultSetr;r=conn.getReult("elect某from管理员");//开始时连接数据库,查询数据,返回结果集,if(r!=null){//把查询结果放到table里面try{//m.etRowCount(0);//table.etModel(mm);while(r.ne某t()){String用户名=r.getString("用户名");String密码=r.getString("密码");String[]cloumn={用户名,密码};m.addRow(cloumn);}t.etModel(m);}catch(E某ceptione){Sytem.out.println(e.toString());}}thi.add(p1,BorderLay out.NORTH);thi.add(p2,BorderLayout.CENTER);thi.add(p3,BorderLayo ut.SOUTH);thi.add(p4,BorderLayout.WEST);thi.add(p5,BorderLayout. EAST);thi.etTitle("用户管理");thi.etSize(600,400);}publicvoidactionPerformed(ActionEvente){ //用户添加if(e.getSource()==add){if(uer.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入用户名","温馨提示",RMATION_MESSAGE);eleif(pa.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入密码","温馨提示",RMATION_MESSAGE);}elemyConnectionconn=newmyConnection();ReultSetr;try{r=conn.getReult("elect某from管理员where用户名='"+uer.getTe某t().toString()+"'");if(r.ne某t()){JOptionPane.howMeageDialog(null,"此用户已经存在","温馨提示",RMATION_MESSAGE);}ele{if(conn.e某ecuteSql("inertinto管value('"+uer.getTe某t().toString()+"','"+pa.getTe某t().toString()+"')"))String[]newUer={uer.getTe某t(),pa.getTe某t()};m.addRow(newUer);t.etModel(m);理员JOptionPane.howMeageDialog(null,"添加成功","温馨提示",RMATION_MESSAGE);}ele{JOptionPane.howMeageDialog(null,"添加失败","温馨提示",RMATION_MESSAGE);}}}catch(E某ceptioner){Sytem.out.println(er.toString());}}//删除}eleif(e.getSource()==del){if(t.getSelectedRow()==-1){JOptionPane.howMeageDialog(null,"请选择你要删除的行","温馨提示",RMATION_MESSAGE);}ele{=",Stringql="deletefrom管理员where用户名'"+t.getValueAt(t.getSelectedRow(),0)+"'";//JOptionPane.howMeage Dialog(null,ql,"温馨提示RMATION_MESSAGE);myConnectionconn=newmyConnection();if(conn.e某ecuteSql(ql)){m.removeRow(t.getSelectedRow());t.etModel(m);//t.removeRowSelectionInterval();JOptionPane.howMeageDialog(null,"成功删除","温馨提示",RMATION_MESSAGE);}ele{JOptionPane.howMeageDialog(null,"未知错误","删除失败",RMATION_MESSAGE);}}}}}claloginFramee某tendJDialogimplementActionLitener//登陆{JPanelp;JTe某tFielduer,pa;JButtonlogin,cancel;publicloginFrame(){p=newJPanel();uer=newJTe某tField(10);pa=newJTe某tField(10);login=newJButton("登录");cancel=newJButton("退出");uer.etTe某t("");pa.etTe某t("");login.addActionLitener(thi);cancel.addActionLitener(thi);p.add(newJLabel("账号"));p.add(uer);p.add(newJLabel("密码"));p.add(pa);p.add(login);p.add(cancel);thi.add(p);thi.etTitle("学生成绩管理系统");JLabelimg=newJLabel(newImageIcon("1.jpg"));p.add(img);thi.etSize(700,600);}publicvoidactionPerformed(ActionEvente){//查找if(e.getSource()==login){if(uer.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入用户名","温馨提示",RMATION_MESSAGE);}eleif(pa.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入密码","温馨提示",RMATION_MESSAGE);}ele{myConnectionconn=newmyConnection();ReultSetr;Stringql="elect某from管理员where用户名='"+uer.getTe某t().toString()+"'and密码='"+pa.getTe某t().toString()+"'";try{r=conn.getReult(ql);if(r.ne某t()){thi.dipoe();//JOptionPane.howMeageDialog(null,"此用户已经存在","温馨提示",RMATION_MESSAGE);ql="elect某from学生成绩表";mainFramemf=newmainFrame();mf.etTitle("学生成绩管理系统");mf.etSize(600,486);mf.frehTable(ql);mf.etViible(true);mf.addWindowLitener(newWindowAdapter(){publicvoidwindowCloing(WindowEvente){Sytem.e某it(0);}});}ele{JOptionPane.howMeageDialog(null,"用户名或密码错误","登录失败",RMATION_MESSAGE);}}catch(E某ceptioner){Sytem.out.println(er.toString());}}}}//全部显示}if(e.getSource()==cancel){Sytem.e某it(0);}。
Java实现功能简单的学生管理系统(附带源代码)
Java实现功能简单的学⽣管理系统(附带源代码)这⼏天Java学了点新的知识,打算要⽤这些知识做⼀个⽐较简单的管理系统,实战⼀下⼦,代码中的功能简洁,可能不多,但是作为⼀个练⼿来了解⼀个项⽬是怎么样⼀点⼀点思考的还是不错的⼀.代码中要实现的功能正所谓⼀个管理系统不可缺少的功能就是"增删查改"。
该程序添加学⽣信息进⽽来实现1.根据学号查找2.根据姓名查找3.根据学号删除4.根据学号修改⼆.实现中所⽤到的技术这个程序主要是针对hashmap的应⽤,以及接⼝的实现⽽呈现出来的,还有如何利⽤增改删除来实现功能。
三.原理解析在实现出这个功能的过程还是有⼀些知识点遗漏了,⽐如什么hashmap容器中的get(),key值之类的是什么了,怎么⽤的,都忘记了,还有⼀些⼩的概念都忘记了,那下⾯我就说⼀下,或许对于你们会的⼈来说很简单,再简单不过的了,但是我还是总结⼀下⼦吧!或许恰巧有的⼈也正好这个知识点忘记了。
[1] .implements和extends的区别1.extends是继承⽗类的,只要那个类不是声名为final或者那个类定义为abstract就能继承2.JAVA中不⽀持多继承,但可以⽤接⼝来实现,这是implements就出现了3.继承只能继承⼀个类,但是implements可以实现多个接⼝,⽤逗号分隔开就好啦!例如:class A extends B implements C D也就是说extends是继承类,implements是实现接⼝类和接⼝是不同的:类⾥是由程序实现的,⽽接⼝⽆程序实现,只可以预定义⽅法[2] Hashmap中put()过程的源码是JDK1.8的源码。
JDK1.8中,Hashmap将基本元素由Entry换成了Node,不过查看源码后发现换汤不换药,这⾥没啥好说的。
public V put(K key, V value) {return putVal(hash(key), key, value, false, true);}final V putVal(int hash, K key, V value, boolean onlyIfAbsent,boolean evict) {Node<K,V>[] tab; Node<K,V> p; int n, i;// 判断数组是否为空,长度是否为0,是则进⾏扩容数组初始化if ((tab = table) == null || (n = tab.length) == 0)n = (tab = resize()).length;// 通过hash算法找到数组下标得到数组元素,为空则新建if ((p = tab[i = (n - 1) & hash]) == null)tab[i] = newNode(hash, key, value, null);else {Node<K,V> e; K k;// 找到数组元素,hash相等同时key相等,则直接覆盖if (p.hash == hash &&((k = p.key) == key || (key != null && key.equals(k))))e = p;// 该数组元素在链表长度>8后形成红⿊树结构的对象,p为树结构已存在的对象else if (p instanceof TreeNode)e = ((TreeNode<K,V>)p).putTreeVal(this, tab, hash, key, value);else {// 该数组元素hash相等,key不等,同时链表长度<8.进⾏遍历寻找元素,有就覆盖⽆则新建for (int binCount = 0; ; ++binCount) {if ((e = p.next) == null) {// 新建链表中数据元素,尾插法p.next = newNode(hash, key, value, null);if (binCount >= TREEIFY_THRESHOLD - 1) // -1 for 1st// 链表长度>=8 结构转为红⿊树treeifyBin(tab, hash);break;}if (e.hash == hash &&((k = e.key) == key || (key != null && key.equals(k))))break;if (e != null) { // existing mapping for keyV oldValue = e.value;// onlyIfAbsent默认falseif (!onlyIfAbsent || oldValue == null)e.value = value;afterNodeAccess(e);return oldValue;}}++modCount;// 判断是否需要扩容if (++size > threshold)resize();afterNodeInsertion(evict);return null;}基本过程如下:检查数组是否为空,执⾏resize()扩充;在实例化HashMap时,并不会进⾏初始化数组)通过hash值计算数组索引,获取该索引位的⾸节点。
学生信息管理系统java课程设计(含源代码)
JAVA程序设计课程设计报告课题: 学生信息管理系统姓名:学号:同组姓名:专业班级:指导教师:设计时间:评阅意见:评定成绩:指目录一、系统描述 (2)1、需要实现的功能 (3)2、设计目的 (3)二、分析与设计 (3)1、功能模块划分 (3)2、数据库结构描述 (4)3、系统详细设计文档 (6)4、各个模块的实现方法描述 (9)5、测试数据及期望结果 (11)三、系统测试 (16)四、心得体会 (23)五、参考文献 (24)六、附录 (24)一、系统描述1、需求实现的功能1.1、录入学生基本信息的功能学生基本信息主要包括:学号、姓名、年龄、出生地、专业、班级总学分,在插入时,如果数据库已经存在该学号,则不能再插入该学号。
1.2、修改学生基本信息的功能在管理员模式下,只要在表格中选中某个学生,就可以对该学生信息进行修改。
1.3、查询学生基本信息的功能可使用“姓名”对已存有的学生资料进行查询。
1.4、删除学生基本信息的功能在管理员模式下,只要选择表格中的某个学生,就可以删除该学生。
1.5、用户登陆用不同的登录权限可以进入不同的后台界面,从而实现权限操作。
1.6、用户登陆信息设置可以修改用户登陆密码2、设计目的学生信息管理系统是一个教育单位不可缺少的部分。
一个功能齐全、简单易用的信息管理系统不但能有效地减轻学校相关工作人员的工作负担,它的内容对于学校的决策者和管理者来说都至关重要。
所以学生信息管理系统应该能够为用户提供充足的信息和快捷的查询手段。
但一直以来人们使用传统人工的方式管理文件档案、统计和查询数据,这种管理方式存在着许多缺点,如:效率低、保密性差、人工的大量浪费;另外时间一长,将产生大量的文件和数据,这对于查找、更新和维护都带来了不少困难。
随着科学技术的不断提高,计算机科学日渐成熟,其强大的功能已为人们深刻认识,它已进入人类社会的各个领域并发挥着越来越重要的作用。
作为计算机应用的一部分,使用计算机对学校的各类信息进行管理,具有手工管理无法比拟的优点。
java学籍管理系统源代码
java学籍管理系统源代码————————————————————————————————作者:————————————————————————————————日期:package zuoye;//主类import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.Hashtable;public class ManagerWindow extends JFrame implements ActionListener {InputStudent 基本信息录入=null;ModifySituation 基本信息修改=null;Inquest 基本信息查询=null;Delete 基本信息删除=null;JPanel pCenter,p,p9;TextField txtName,txtPassword;Label lblTitle,lblName,lblPassword;Button btnSubmit,btnReset,guanbi;Panel p1,p11,p12,p2,p13,p14,p15;JMenuBar bar;ImageIcon icon;JMenu fileMenu;JMenuItem 录入,修改,查询,删除,欢迎,退出,关于;Container con=null;Hashtable 基本信息=null;File file=null;CardLayout card=null;JLabel label=null;JLabel label2;public ManagerWindow(){p=new JPanel();lblName=new Label("管理员帐号:");txtName=new TextField(10);lblPassword=new Label("密码:");txtPassword=new TextField(10);txtPassword.setEchoChar('*');btnSubmit = new Button("提交");btnReset = new Button("重置");guanbi=new Button("关闭");p11=new Panel();p12=new Panel();p13=new Panel();p14=new Panel();p15=new Panel();p11.add(lblName);p11.add(txtName);p12.add(lblPassword);p12.add(txtPassword);txtName.addActionListener(this);txtPassword.addActionListener(this);p13.add(btnSubmit);btnSubmit.setBackground(Color.YELLOW);p13.add(btnReset);btnReset.setBackground(Color.YELLOW);p13.add(guanbi);guanbi.setBackground(Color.YELLOW);btnSubmit.addActionListener(this);btnReset.addActionListener(this);guanbi.addActionListener(this);p.setLayout(new GridLayout(10,1));p.add(p14);p.add(p15);p.add(p11);p.add(p12);p.add(p13);p.setBackground(Color.gray);p9=new JPanel();icon=new ImageIcon("123.jpg");label2=new JLabel(icon,JLabel.LEFT);label=new JLabel("欢迎使用学生基本信息管理系统",JLabel.CENTER); label.setFont(new Font("TimesRoman",Font.BOLD,24));label.setForeground(Color.red);p9.setOpaque(true);p9.add(label);p9.add(label2);录入=new JMenuItem("录入学生基本信息");修改=new JMenuItem("修改学生基本信息");查询=new JMenuItem("查询学生基本信息");删除=new JMenuItem("删除学生基本信息");欢迎=new JMenuItem("欢迎界面");退出=new JMenuItem("退出");关于=new JMenuItem("关于我们");bar=new JMenuBar();fileMenu=new JMenu("菜单选项");fileMenu.add(录入);fileMenu.add(修改);fileMenu.add(查询);fileMenu.add(删除);fileMenu.add(欢迎);fileMenu.add(关于);fileMenu.add(退出);fileMenu.enable(false);bar.add(fileMenu);setJMenuBar(bar);基本信息=new Hashtable();录入.addActionListener(this);修改.addActionListener(this);查询.addActionListener(this);删除.addActionListener(this);欢迎.addActionListener(this);退出.addActionListener(this);关于.addActionListener(this);card=new CardLayout();con=getContentPane();pCenter=new JPanel();pCenter.setLayout(card);pCenter.setBackground(Color.black);file=new File("作业.txt");if(!file.exists()){try{FileOutputStream out=new FileOutputStream(file);ObjectOutputStream objectOut=new ObjectOutputStream(out);objectOut.writeObject(基本信息);objectOut.close();out.close();}catch(IOException e){}}基本信息录入=new InputStudent(file);基本信息修改=new ModifySituation(file);基本信息查询=new Inquest(this,file);基本信息删除=new Delete(file);pCenter.add(p,BorderLayout.CENTER);pCenter.add("欢迎语界面",p9);pCenter.add("录入界面",基本信息录入);pCenter.add("修改界面",基本信息修改);pCenter.add("删除界面",基本信息删除);con.add(pCenter,BorderLayout.CENTER);con.validate();addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){System.exit(0);}});setVisible(true);setBounds(500,200,450,400);validate();}public void clear(){txtName.setText("");txtPassword.setText("");}@SuppressWarnings("deprecation")public void submit(){String n=txtName.getText();String paw=txtPassword.getText();if(n.equals("admin") && paw.equals("1234")){JOptionPane.showMessageDialog(this,"合法用户,欢迎进入本系统");card.show(pCenter,"欢迎语界面");fileMenu.enable();}else{JOptionPane.showMessageDialog(this,"非法用户,禁止进入本系统");}}public void actionPerformed(ActionEvent e){if(e.getSource()==录入){card.show(pCenter,"录入界面");}else if(e.getSource()==修改){card.show(pCenter,"修改界面");}else if(e.getSource()==查询){基本信息查询.setVisible(true);}else if(e.getSource()==删除){card.show(pCenter,"删除界面");}else if(e.getSource()==欢迎){card.show(pCenter,"欢迎语界面");}else if(e.getSource()==退出){System.exit(0);}else if(e.getSource()==关于){JOptionPane.showMessageDialog(this,"五块二小组:常永恒,孙东升,李强,吴春亮,涂留定");}String s=e.getActionCommand();if(s.equals("重置")){clear();}else if(s.equals("提交")){submit();}else if(e.getSource()==txtName){txtPassword.requestFocus();}else if(e.getSource()==txtPassword){submit();}else if(s.equals("关闭")){System.exit(0);}}public static void main(String args[]){new ManagerWindow();}}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
学生学籍管理详细设计学号: _______________ 姓名: _______________ 班级: ______________、设计题目: 学生学籍管理 :设计内容:设计 GUI 学生学籍管理界面,用户可以加入学生信息,并对基本信息进行修 改,添加,查询,删除。
三:设计要求: 进行简单的学生信息管理。
四:总体设计(1)登陆界面的设计 (2) (3) (4) (5)(6) (7)事件响应的处理 五:具体设计 (1)程序结构的说明:入口程序: student.java; 登陆界面程序: mainframe.java;主窗体程序: interfac.java; 添加信息窗口程序 修改信息窗口程序 查询信息窗口程序 删除信息窗口程序 程序数据连接: DatabaseConn.java; (2) 程序代码及分析说明 A. 程序源代码(已提交)B. Student.java 是程序的入口。
使登录窗口位于窗口中间,并且不可改变窗口 大小。
C. mainframe.java 是程序的登陆窗体。
输入用户名和密码(用户名和密码在数 据库的 password 表中)点击“进入系统”,然后登陆界面消失;出现要操作的界 面(屏幕左上角) 。
D. tj.java 是添加信息界面。
添加基本信息后,点击“添加信息”按钮,将信息 加入 xinxiE. xg.java 是修改信息界面。
输入要修改的学号或姓名(两者数其一或全部输 入),并输入所有信息,点击“修改信息”按钮(如果数据库中不存在此学号, 则弹出对话框“无此学生信息” ),若有则修改。
F. sc.java 是删除信息界面。
输入要删除的学生的学号, 点击“删除信息” 按钮, 弹出确认删除对话框,即可删除该生信息。
G. cx.java 是查询信息界面。
输入要查询的学生学号,点击“信息查询”按钮, 在相应的文本区里显示查询的信息。
H:源代码//student.java: 程序的入口。
初始化界面,使主界面位于屏幕中间,且用户不 能改变大小 // 功能:完成程序的执行顺序主窗体的设计 添加学生信息窗体 查询学生信息窗体 修改学生信息窗体 删除学生信息窗体A B C D E F. G H tj.java; xg.java; cx.java; sc.java; 表中。
import javax.swing.UIManager;import java.awt.*;import java.sql.*;//import screenpublic class student{boolean packFrame=false;//JFrame frame=new JFrame();public student(){mainframe frame=new mainframe();if(packFrame){frame.pack();}else{frame.validate();}Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();Dimension frameSize=frame.getSize();if(frameSize.height>screenSize.height) {frameSize.height=screenSize.height;} if(frameSize.width>screenSize.width){frameSize.width=screenSize.width;}frame.setLocation((screenSize.width-frameSize.width)/2,(screenSize.height-frameSize.height)/2);frame.setVisible(true);}public static void main(String[] args){try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName( ));} catch(Exception e){e.printStackTrace();}new student();}// 数据库连接//package sql.database;import java.sql.*;public class DatabaseConn{private static String user="";private static String password="";private Connection conn=null;private Statement stmt=null;private ResultSet rs=null;static{ try{C加载驱动lass.forName("sun.jdbc.odbc.JdbcOdbcDriver");//} catch(ClassNotFoundException e){}}// 创建数据库连接对象public Connection getConnection(){try{conn=DriverManager.getConnection("jdbc:odbc:stu",user,password);return conn;}catch(SQLException e){return null;}}public Statement createStat(){try{ conn=getConnection(); stmt=conn.createStatement(); returnstmt;}catch(SQLException e) {return null;}}public ResultSet getRs(String sql){try{conn=getConnection();//... stmt=createStat(); rs=stmt.executeQuery(sql); return rs;}catch(SQLException e){return null; }}public void close(){try{if(rs!=null)rs.close(); if(stmt!=null) stmt.close(); if(conn!=null)conn.close(); }catch(SQLException ex) {ex.printStackTrace(); }}//mainframe.java import java.awt.*; import java.awt.event.*; importjavax.swing.*; import java.sql.*; public class mainframe extends JFrame {static mainframe s;static JPanel pan=new JPanel(); static JLabel label1 = new JLabel(" static JLabel label2 = new JLabel("static JTextField textField1 = newJTextField(); static JPasswordField password = new JPasswordField(); static JButton button1 = new JButton("进入系统 ");implements ActionListener用 户 "); 密 码 ");static JRadioButton radioButton1=new JRadioButton(" 管理员”初始状态被选中 static JRadioButton radioButton2=new JRadioButton(" static JRadioButton radioButton3=new JRadioButton(" ButtonGroup buttonGroup=new ButtonGroup(); public mainframe(){JLabel label=new JLabel(new ImageIcon(" 图片 44.jpg")); label.setSize(400,400);pan.add(label); pan.setLayout(null); pan.setSize(400,400); this.setTitle(" 学籍管理系统 "); this.setSize(400,400); this.setLayout(null);label1.setBounds(100,25,49,20); textField1.setBounds(155,24,120,20); label2.setBounds(100,62,49,20); password.setBounds(155,61,120,20); button1.setBounds(150,200,101,22);radioButton1.setBounds(105,120,80,20); radioButton2.setBounds(180,120,60,20);radioButton3.setBounds(240,120,60,20); button1.addActionListener(this); buttonGroup.add(radioButton1);buttonGroup.add(radioButton2); buttonGroup.add(radioButton3); this.add(radioButton1); this.add(radioButton2); this.add(radioButton3); this.add(label1); this.add(label2); this.add(textField1); this.add(password); this.add(button1); this.add(pan);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true);}public static void main(String[] args) {new mainframe(); }public void actionPerformed(ActionEvent e)管理员 ",true);// 学生"); 教师");}else{JOptionPane.showMessageDialog(null," 有误");}}if(radioButton2.isSelected())// { try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(s,ce.getMessage()); }try{Connection conDriverManager.getConnection("jdbc:odbc:stu","sa","");Statement stmt = con.createStatement();ResultSet rs = stmt.executeQuery("select * from password where 户 名 = '"+textField1.getText()+"' and 密 码 '"+password.getText()+"'"); if(textField1.getText().equals("")||password.getText().equals("")) {JOptionPane.showMessageDialog(this,"不可为空! ");}else if(rs.next()) { new interfac();}else{JOptionPane.showMessageDialog(this,"if(radioButton1.isSelected())// { if(textField1.getText().equals("syc")password.getText().equals("123")){ interfac b=new interfac(); this.dispose(); //JOptionPane.showMessageDialog(null," 登陆成功 "); }else if("".equals(textField1.getText())"".equals(password.getText()) ){ JOptionPane.showMessageDialog(null," 用户名或密码不能为 管理员 && || 用户名或密码输入学生 用户名或密码您的输入有误 ");}//stmt.close();}catch (SQLException se){JOptionPane.showMessageDialog(s,se.getMessage());}}}}//interface.java import java.awt.*;import java.awt.event.*; import javax.swing.*;public class interfac extends JFrame implements ActionListener{static JMenuBar jMenuBar = new JMenuBar();// static JMenu jMenuFile = new JMenu(" 文件 ");// static JMenu jMenuExit = new JMenu("退出 ");static JMenuItem jMenuItem1 = new JMenuItem(" static JMenuItem jMenuItem2 = new JMenuItem(" static JMenuItem jMenuItem3 = new JMenuItem(" static JMenuItem jMenuItem4 = new JMenuItem(" JLabel label3 = new JLabel(" JLabel label4 = new JLabel(" JButton button2 = new JButton(" JButton button3 = new JButton(" JButton button4 = new JButton(" JButton button5 = new JButton(" public interfac(){this.setTitle(" 学籍管理系统 "); this.setLayout(null);this.setSize(400,400); label3.setBounds(158,92,98,33); label3.setFont(new Font("Dialog",Font.PLAIN,15)); label4.setFont(new Font("Dialog",Font.BOLD,20));label4.setBounds(157,37,280,40); button2.setBounds(74,136,97,33); button3.setBounds(226,136,97,33); button4.setBounds(74,185,97,33); button5.setBounds(226,185,97,33); this.add(button2); this.add(button3); this.add(button4);菜单条 菜单项添加信息 ");// 菜单子项 修改信息 "); 信息查询 "); 删除信息 ");请选择操作项 "); 学籍管理系统 "); 添加信息 "); 修改信息 "); 信息查询 "); 删除信息 ");static static static staticstatic staticthis.add(button5); this.add(label3); this.add(label4); setJMenuBar(jMenuBar);jMenuFile.add(jMenuItem1);// ”文件“菜单项中加入子菜单 jMenuFile.add(jMenuItem2);jMenuFile.add(jMenuItem3); jMenuFile.add(jMenuItem4);jMenuBar.add(jMenuFile);// 将菜单项加入菜单条 jMenuBar.add(jMenuExit); button2.addActionListener(this);// button3.addActionListener(this); button4.addActionListener(this);button5.addActionListener(this); jMenuItem1.addActionListener(this);// jMenuItem2.addActionListener(this); jMenuItem3.addActionListener(this); jMenuItem4.addActionListener(this); jMenuExit.addActionListener(this);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); }public static void main(String[] args) {interfac a=new interfac();}public void actionPerformed(ActionEvent e) // {if(e.getSource()==jMenuExit) {System.exit(0);}else if(e.getSource()==jMenuItem1||e.getSource()==button2) {try{ tj a=new tj(); }catch(Exception ee) {}}else if(e.getSource()==jMenuItem2||e.getSource()==button3) {try{ xg a=new xg(); }catch(Exception ed)本窗口向按钮事件源注册 本窗口菜单子项注册 按钮事件的处理{}} else if(e.getSource()==jMenuItem3||e.getSource()==button4) {try{cx a=new cx();} catch(Exception ec){}} elseif(e.getSource()==jMenuItem4||e.getSource()==button5)try{sc a=new sc(); }catch(Exception es){}添加界面 import javax.swing.*; import java.awt.*; importjava.awt.event.*; import java.sql.*;public class tj extends JFrame implements ActionListener {static tj s;static JLabel label1 = new JLabel(" 学号 :");static JTextField textField1 = new JTextField(""); static JLabel label2 = new JLabel(" 姓名 :");static JTextField textField2 = new JTextField(""); static JLabel label3 = new JLabel(" 性别 :");static JTextField textField7=new JTextField(""); static JLabel label4 = new JLabel(" 出生日期 :"); static JTextField textField3 = new JTextField("");static JLabel label5 = new JLabel(" 政治面貌 :"); static JTextField textField8=new JTextField("");static JLabel label6 = new JLabel(" 籍贯 ");static JTextField textField4 = new JTextField(""); static JLabel label7 = new JLabel(" 系别 :");static JTextField textField9 = new JTextField(""); static JLabel label8 = new JLabel(" 专业 :");static JTextField textField5 = new JTextField(""); static JButton button1 = new JButton(" 增加 "); public tj() {}}//tj.javathis.setTitle(" 增加学生信息"); this.setLayout(null);this.setSize(400,400); label1.setBounds(30, 11, 51, 33); textField1.setBounds(86, 16, 74, 22); label2.setBounds(162, 11, 51, 33); textField2.setBounds(192, 16, 44, 22); label3.setBounds(241, 11, 70, 33); textField7.setBounds(275, 15, 50, 25); label4.setBounds(31, 53, 55, 33); textField3.setBounds(86, 58, 74, 22);label5.setBounds(241, 53, 70, 33); textField8.setBounds(296, 57, 72, 25);label6.setBounds(163, 53, 26, 33); textField4.setBounds(191, 58, 44, 22);label7.setBounds(30, 94, 50, 33); textField9.setBounds(86,94,74,22);label8.setBounds(163, 94, 51, 33); textField5.setBounds(190, 99, 178, 22); button1.setBounds(25,241,80,33); button1.addActionListener(this);this.add(label1); this.add(label2); this.add(label3); this.add(label4);this.add(label5); this.add(label6); this.add(label7); this.add(label8);this.add(textField1); this.add(textField2); this.add(textField3); this.add(textField4); this.add(textField5); this.add(textField7); this.add(textField8); this.add(textField9); this.add(button1);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);this.setVisible(true);} public static void main(String[] args) throws Exception{ tj a=new tj();a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent e)// { if (e.getSource() == button1) {事件处理程序try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch (ClassNotFoundException ce){ JOptionPane.showMessageDialog(s,ce.g}etMessage());}try{Connection con DriverManager.getConnection("jdbc:odbc:stu","sa"," ");Statement stmt = con.createStatement();ResultSet rs=stmt.executeQuery("select * from xinxi where 学号='"+textField1.getText()+"'"); if(rs.next()) {JOptionPane.showMessageDialog(null," 此学号已经被注册");}else{ stmt.execute("insert into xinxi (学号,姓名, 性别, 出生日期, 政治面貌,籍贯, 系别, 专业) values ('"+ textField1.getText()+"','"+textField2.getText()+"','"+textField7.getText()+"','"+ textField3.getText()+"','"+textField8.getText() +"','"+textField4.getText()+"','"+ textField9.getText()+"','"+textField5.getText()+"')");JOptionPane.showMessageDialog(null," 添加信息成功");}}catch (SQLException se){JOptionPane.sh}o w M e s s a g e D i a l o g ( s , s e . g e t M e s s a g e () );}}}}//xg.java 修改界面import javax.swing.*; import java.awt.*;import java.awt.event.*;import java.sql.*;public class xg extends JFrame implements ActionListener {static xg s;static JLabel label1 = new JLabel(" 学号:");static JTextField textField1 = new JTextField(""); static JLabel label2 = new JLabel(" 姓名:");static JTextField textField2 = new JTextField(""); static JLabel label3 = new JLabel(" 性别:");static JTextField textField7=new JTextField("");static JLabel label4 = new JLabel(" 出生日期:");static JTextField textField3 = new JTextField("");static JLabel label5 = new JLabel(" 政治面貌:");static JTextField textField8=new JTextField("");static JLabel label6 = new JLabel(" 籍贯"); static JTextField textField4 = new JTextField(""); static JLabel label7 = new JLabel(" 系别:");static JTextField textField9 = new JTextField(""); static JLabel label8 = new JLabel(" 专业:"); static JTextField textField5 = new JTextField(""); static JButton button2=new JButton(" 修改");public xg(){this.setTitle(" 修改学生信息"); this.setLayout(null);this.setSize(400,400); label1.setBounds(30, 11, 51, 33); textField1.setBounds(86, 16, 74, 22); label2.setBounds(162, 11, 51, 33); textField2.setBounds(192, 16, 44, 22); label3.setBounds(241, 11, 70, 33); textField7.setBounds(275, 15, 50, 25); label4.setBounds(31, 53, 55, 33); textField3.setBounds(86, 58, 74, 22);label5.setBounds(241, 53, 70, 33); textField8.setBounds(296, 57, 72, 25);label6.setBounds(163, 53, 26, 33);}textField4.setBounds(191, 58, 44, 22); label7.setBounds(30, 94, 50, 33); textField9.setBounds(86,94,74,22); label8.setBounds(163, 94, 51, 33);textField5.setBounds(190, 99, 178, 22); button2.setBounds(115,241,80,33); button2.addActionListener(this);this.add(label1); this.add(label2); this.add(label3); this.add(label4); this.add(label5); this.add(label6); this.add(label7); this.add(label8);this.add(textField1); this.add(textField2); this.add(textField3); this.add(textField4); this.add(textField5); this.add(textField7); this.add(textField8); this.add(textField9); this.add(button2); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setVisible(true); }public static void main(String[] args) throws Exception { xg a=new xg();a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent e)// { if(e.getSource()==button2) {try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch (ClassNotFoundException ce){JO pti on Pa ne .s ho w M es sa ge Di al og (s,ce .g et Mes sage事件处理程序()); try}}{Connection con = DriverManager.getConnection("jdbc:odbc:stu","sa","");Statement stmt = con.createStatement();ResultSet rs=stmt.executeQuery("select * from='"+textField1.getText ()+"'");if(textField1.getText().trim().equals("")) {JOptionPane.showMessageDialog(this,"");}else if(rs.next()){textField2.getText()+"',出='"+textField8.getText()+"', 籍贯 ='"+textField4.getText()+"',专 textField5.getText()+ "'"; try{stmt.executeQuery(updateSql);}catch(SQLException se) {JOptionPane.showMessageDialog(null," 修改成 功");}catc h(SQ LExc eptio n se){JOptionPane.showMessageDialog(s,se.getMessage()); }String='"+textField1.getText()+"', ='"+updateSql="update姓名xinxi set 学 号textField3.getText()+"', 政治面貌xinxi where 学 号学号不可为空!='"+textField7.getText()+"', 生日期 ='"+性别 系别='"+textField9.getText()+"',业='"+//sc.java 删除界面import javax.swing.*; import java.awt.*; importjava.awt.event.*; import java.sql.*;public class sc extends JFrame implements ActionListener {static sc s;static JLabel label1 = new JLabel(" 学号:");static JTextField textField1 = new JTextField(""); static JLabel label2 = new JLabel(" 姓名:");static JTextField textField2 = new JTextField(""); static JLabel label3 = new JLabel(" 性别:");static JTextField textField7=new JTextField(""); static JLabel label4 = new JLabel(" 出生日期:");static JTextField textField3 = new JTextField("");static JLabel label5 = new JLabel(" 政治面貌:");static JTextField textField8=new JTextField("");static JLabel label6 = new JLabel(" 籍贯"); static JTextField textField4 = new JTextField(""); static JLabel label7 = new JLabel(" 系别:");static JTextField textField9 = new JTextField(""); static JLabel label8 = new JLabel(" 专业:"); static JTextField textField5 = new JTextField(""); static JButton button4=new JButton(" 删除");public sc() throws Exception{this.setTitle(" 删除学生信息"); this.setLayout(null);this.setSize(400,400); label1.setBounds(30, 11, 51, 33);textField1.setBounds(86, 16, 74, 22); label2.setBounds(162, 11, 51, 33);textField2.setBounds(192, 16, 44, 22); label3.setBounds(241, 11, 70,33); textField7.setBounds(275, 15, 50, 25); label4.setBounds(31, 53, 55,33); textField3.setBounds(86, 58, 74, 22); label5.setBounds(241, 53, 70,33); textField8.setBounds(296, 57, 72, 25); label6.setBounds(163, 53,26, 33); textField4.setBounds(191, 58, 44, 22); label7.setBounds(30, 94, 50, 33); textField9.setBounds(86,94,74,22);label8.setBounds(163, 94, 51, 33);textField5.setBounds(190, 99, 178, 22);button4.setBounds(295,241,80,33);button4.addActionListener(this);this.add(label1);this.add(label2);this.add(label3);this.add(label4);this.add(label5);this.add(label6);this.add(label7);this.add(label8);this.add(textField1);this.add(textField2);this.add(textField3);this.add(textField4);this.add(textField5);this.add(textField7);this.add(textField8);this.add(textField9);this.add(button4);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setVisible(true);}public static void main(String[] args) throws Exception{sc a= new sc();a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e)//sc{if (e.getSource() == button4){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch (ClassNotFoundException ce){ JOptionPane.showMessageDialog(s,ce.getMessage());}try{ Connection conDriverManager.getConnection("jdbc:odbc:stu","sa","");Statement stmt = con.createStatement();ResultSet rs=stmt.executeQuery("select * from xinxi where 号i'+textField1.getText()+"”');if(textField1.getText().trim().equals("")){JOptionPane.showMessageDialog(this,"");}else if(rs.next()){功!");this.dispose();}else JOptionPane.showMessageDialog(null,"警告",J0 ptio nPan e.WARNING_MESSAGE);catch(Exception ed){ JOptionPane.showMessageDialog(s,ed.getMessage());}}}}//cx.javaimportjavax.swing.*; import java.awt.*;import java.awt.event.*; import java.sql.*;public class cx extends JFrame implements ActionListener {static cx s;static JLabel label1 = new JLabel(" 学号:"); static JTextField textField1 = new JTextField(""); static JLabel label2 = new JLabel(" 姓名 :"); static JTextField textField2 = new JTextField(""); static JLabel label3 = new JLabel(" 性别 :"); static JTextField textField7=new JTextField(""); static JLabel label4 = new JLabel(" 出生日期:") ;static JTextField textField3 = new JTextField(""); static JLabel label5 = new JLabel(" 政治面貌 :");static JTextField textField8=new JTextField(""); static JLabel label6 = new JLabel(" 籍贯 ");static JTextField textField4 = new JTextField(""); static JLabel label7 = new JLabel(" 系别 :"); static JTextField textField9 = new JTextField(""); static JLabel学号不可为空! 确 定要删除该信"," 删 除 确 定JOptionPane.showConfirmDialog(null,"息嘛 ? \n 删 除 的 信 息 将 不 能 恢复 , 继 续 ?",JOptionPane.OK_CANCEL_OPTION);//,JOption.QUESTION_MESSAGE)==0;where 学 号from xinxi stmt.execute("delete ='"+textField1.getText()+"'");JOptionPane.showMessageDialog(null," 删除信息成应信息 "," }无此学号对查询界面label8 = new JLabel(" 专业:");static JTextField textField5 = new JTextField(""); static JButton button3=new JButton(" 查询");public cx() throws Exception{this.setTitle(" 查询学生信息"); this.setLayout(null); this.setSize(400,400); label1.setBounds(30, 11, 51, 33); textField1.setBounds(86, 16, 74, 22); label2.setBounds(162, 11, 51, 33); textField2.setBounds(192, 16, 44, 22); label3.setBounds(241, 11, 70, 33); textField7.setBounds(275, 15, 50, 25); label4.setBounds(31, 53, 55, 33); textField3.setBounds(86, 58, 74, 22); label5.setBounds(241, 53, 70, 33); textField8.setBounds(296, 57, 72, 25); label6.setBounds(163, 53, 26, 33); textField4.setBounds(191, 58, 44, 22); label7.setBounds(30, 94, 50, 33); textField9.setBounds(86,94,74,22); label8.setBounds(163, 94, 51, 33); textField5.setBounds(190, 99, 178, 22); button3.setBounds(205,241,80,33); button3.addActionListener(this);this.add(label1); this.add(label2); this.add(label3); this.add(label4);this.add(label5); this.add(label6); this.add(label7); this.add(label8);this.add(textField1); this.add(textField2); this.add(textField3);this.add(textField4);this.add(textField5);this.add(textField7);this.add(textField8);this.add(textField9);this.add(button3);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setVisible(true);}public static void main(String[] args) throws Exception{cx a=new cx();a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e){if(e.getSource()==button3){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");} catch (ClassNotFoundException ce){ JOptionPane.showMessageDialog(s,ce.getMessage());} try { Connection conDriverManager.getConnection("jdbc:odbc:stu","sa","");Statement stmt = con.createStatement(); ResultSetrs=stmt.executeQuery("select='"+textField1.getText()+"'");if(textField1.getText().trim().equals("")) {JOptionPane.showMessageDialog(this," ");}else if(rs.next()){textField2.setText(rs.getString("textField7.setText(rs.getString("textField3.setText(rs.getString("textField8.setText(rs.getString("textField4.setText(rs.getString("from xinxi where 学号学号不可为空!姓名")); 性别")); 出生日期")); 政治面貌"));籍贯"));textField9.setText(rs.getString("textField5.setText(rs.getString(" } else{JOptionPane.showMessageDialog(this,"} catch (SQLException se ){JOptionPane.showMessageDialog (s,se.getMessage ());}}}} I. 运行说明在 DOS 窗 口输入 javac student.javajava student 运行程序。