学生学籍管理系统(含java源代码)[1]

合集下载

java学生信息管理系统源代码

java学生信息管理系统源代码

java学⽣信息管理系统源代码本⽂实例为⼤家分享了java学⽣信息管理系统的具体代码,实现学⽣信息:增加 int[] a=new int[9] 、删除、查找、更改,供⼤家参考,具体内容如下/*学⽣信息管理系统,实现学⽣信息:*增加 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 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);System.out.print("请输⼊要删除的学号:");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("数据成功删除!");System.out.println("系统返回主菜单!");this.menu();}}}public void look()throws IOExceptionFileReader 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("数据已成功修改!");}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学籍管理系统源代码————————————————————————————————作者:————————————————————————————————日期: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();}}。

java 编写简单的学生信息管理系统--附上源码

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 程序设计 课程设计陈述宇文皓月课 题: 学生信息管理系统 姓 名: 学 号: 同组姓名: 专业班级: 指导教师: 设计时间:目 录1、需要实现的功能32、设计目的3 1、功能模块划分32、数据库结构描述43、系统详细设计文档64、各个模块的实现方法描述95、测试数据及期望结果11一、系统描述1、需求实现的功能1.1、录入学生基本信息的功能学生基本信息主要包含:学号、姓名、年龄、出生地、专业、班级总学分,在拔出时,如果数据库已经存在该学号,则不克不及再拔出该学号。

1.2、修改学生基本信息的功能在管理员模式下,只要在表格中选中某个学生,就可以对该学生信息进行修改。

评阅意见:评定成绩:指导老师签名:年 月 日1.3、查询学生基本信息的功能可使用“姓名”对已存有的学生资料进行查询。

1.4、删除学生基本信息的功能在管理员模式下,只要选择表格中的某个学生,就可以删除该学生。

1.5、用户登陆用分歧的登录权限可以进入分歧的后台界面,从而实现权限操纵。

1.6、用户登陆信息设置可以修改用户登陆密码2、设计目的学生信息管理系统是一个教育单位不成缺少的部分。

一个功能齐全、简单易用的信息管理系统不单能有效地减轻学校相关工作人员的工作负担,它的内容对于学校的决策者和管理者来说都至关重要。

所以学生信息管理系统应该能够为用户提供充足的信息和快捷的查询手段。

但一直以来人们使用传统人工的方式管理文件档案、统计和查询数据,这种管理方式存在着许多缺点,如:效率低、保密性差、人工的大量浪费;另外时间一长,将发生大量的文件和数据,这对于查找、更新和维护都带来了很多困难。

随着科学技术的不竭提高,计算机科学日渐成熟,其强大的功能已为人们深刻认识,它已进入人类社会的各个领域并发挥着越来越重要的作用。

作为计算机应用的一部分,使用计算机对学校的各类信息进行管理,具有手工管理无法比较的优点。

例如:检索迅速、查询方便、效率高、可靠性好、存储量大、保密性好、寿命长、成本低等。

JAVA+SQL学生学籍管理系统代码及实验报告

JAVA+SQL学生学籍管理系统代码及实验报告

学生学籍管理系统1课程设计目的、设计内容与需求分析1.1 课程设计目的通过本次课程设计的实践操作,能够让学生懂得Java、SQL的各种相关知识的使用,真正的提高学生独立开发设计Java程序,把课堂上的知识运用在实践上,一门编程语言只有在不断实践操作和练习上才会有进步。

1.2软件设计内容学生学籍管理系统,可用于学校等机构的学生信息管理,查询,更新与维护,使用方便,易用性强,图形界面清晰明了。

该软件用java语言编写,用SQLServer2005数据库作为后台的数据库进行信息的存储,用SQL语句完成添加,查询,修改,删除的操作。

用ODBC驱动实现前台Java与后台SQL数据库的连接。

Java语言跨平台性强,可以在windows,linux,ubuntu等系统下使用,方便简单,安全性好。

SQLServer2005数据库高效安全,两者结合可相互利用各自的优势。

系统可供输入的属性有“学号”,“姓名”,“性别”,“班级”,“学院”,“籍贯”。

该系统实现的大致功能:1.管理员登陆界面。

该界面可以输入管理员号,登陆密码。

用户通过验证通过后方可进入管理系统。

一定程度上保证了信息安全性,防止他人未经允许篡改学生信息。

2.查询学生信息。

可以选择由用户选择“显示系统中当前的所有学生信息”。

也可以选择按照“某一个学号查询该学号的学生信息”。

查询到的信息会在窗口中依次显示出来。

3.添加学生信息。

可以按照图形的界面的显示依次输入新学生的“学号”,“姓名”,“性别”,“班级”,“学院”,“籍贯”。

完成新纪录的添加。

4.修改学生信息。

可以选择按照“学号”或者“姓名”找到该学生的学生信息并输入要修改的属性,并输入新的数据。

完成对学生记录的修改。

5.删除学生记录。

可以根据输入的“学号”或者”姓名”进行删除的操作。

1.3需求分析在一些学校等机构,随着学生数量的不断增加,学生的信息不断增多,人工管理信息的难度也越来越大。

而且效率也是很低的。

学生信息管理系统源代码java

学生信息管理系统源代码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课程设计_学籍管理系统代码

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)+代码【范本模板】

学生信息管理系统设计1、系统简介本系统提供了学生信息管理中常见的基本功能,主要包括管理员和学生两大模块.管理员的主要功能有对学生信息和课程信息进行增加、删除、修改、查找等操作,对选课信息进行管理,对成绩信息和用户信息进行修改、查找等操作。

学生的主要功能有对学生信息和成绩信息进行查看,对个人的密码信息进行修改等。

2、功能设计2.1 需求分析本系统需要实现的功能:(1)、管理员对学生信息和课程信息进行增加、删除、修改、查找等操作,对选课信息进行管理,对成绩信息和用户信息进行修改、查找等操作。

(2)、学生对学生信息和成绩信息进行查看,对个人的密码信息进行修改等。

2。

2 总体设计学生信息管理系统主要包括管理员和学生两大模块。

管理员模块包括:学生信息管理、课程信息管理、选课信息管理、成绩信息管理、用户信息管理等。

用户模块包括:学生信息查看、成绩信息查看、个人信息管理等。

系统总体结构如图所示.总体结构图2。

3 模块详细设计1、学生信息管理模块学生信息管理模块包括增加、删除、修改、查询、显示全部等。

具体的结构图如图所示.学生信息管理模块结构图2、课程信息管理模块课程信息管理模块包括增加、删除、修改、查询、显示全部等.具体的结构图如图所示。

课程信息管理模块结构图3、选课信息管理模块选课信息管理模块包括查询、显示全部等。

具体的结构图如图所示。

选课信息管理模块结构图4、成绩信息管理模块成绩信息管理模块包括修改成绩、查询、显示全部等。

具体的结构图如图所示。

成绩信息管理模块结构图5、用户信息管理模块用户信息管理模块包括修改、查询、显示全部等。

具体的结构图如图所示.用户信息管理模块结构图3、数据库设计在数据库student中共有4张数据表:s(学生信息表)、c(课程信息表)、sc(选课信息表)、unpw(用户信息表),下面定义每张表的字段名称和数据类型。

字段名称数据类型描述sno char (10) 学号,关键字sn char (20) 姓名sa int 年龄ss char (10)性别sd char (10)院系字段名称数据类型描述cno char (10)课程号,关键字cn char (30)课程名pcno char (10)先行课程号字段名称数据类型描述sno char (10) 学号,关键字cno char (10)课程号,关键字g int 成绩字段名称数据类型描述un char (10) 用户名,关键字pw char (10) 密码qx int 角色4、界面库设计1、学生信息管理系统的登录学生信息管理系统可由管理员和学生两种身份的人使用。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

学生学籍管理详细设计学号:____________姓名:____________班级:____________一、设计题目:学生学籍管理二:设计内容:设计GUI学生学籍管理界面,用户可以加入学生信息,并对基本信息进行修改,添加,查询,删除。

三:设计要求:进行简单的学生信息管理。

四:总体设计(1)登陆界面的设计(2)主窗体的设计(3)添加学生信息窗体(4)查询学生信息窗体(5)修改学生信息窗体(6)删除学生信息窗体(7)事件响应的处理五:具体设计(1)程序结构的说明:A.入口程序:student.java;B.登陆界面程序:mainframe.java;C.主窗体程序:interfac.java;D.添加信息窗口程序:tj.java;E.修改信息窗口程序:xg.java;F.查询信息窗口程序:cx.java;G.删除信息窗口程序:sc.java;H.程序数据连接:DatabaseConn.java;(2)程序代码及分析说明A.程序源代码(已提交)B.Student.java是程序的入口。

使登录窗口位于窗口中间,并且不可改变窗口大小。

C.mainframe.java是程序的登陆窗体。

输入用户名和密码(用户名和密码在数据库的password表中)点击“进入系统”,然后登陆界面消失;出现要操作的界面(屏幕左上角)。

D.tj.java是添加信息界面。

添加基本信息后,点击“添加信息”按钮,将信息加入xinxi表中。

E.xg.java是修改信息界面。

输入要修改的学号或姓名(两者数其一或全部输入),并输入所有信息,点击“修改信息”按钮(如果数据库中不存在此学号,则弹出对话框“无此学生信息”),若有则修改。

F.sc.java是删除信息界面。

输入要删除的学生的学号,点击“删除信息”按钮,弹出确认删除对话框,即可删除该生信息。

G.cx.java是查询信息界面。

输入要查询的学生学号,点击“信息查询”按钮,在相应的文本区里显示查询的信息。

H:源代码//student.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();}DimensionscreenSize=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,(screenSiz e.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{Class.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();return stmt;}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.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class mainframe extends JFrame implements ActionListener {static mainframe s;static JPanel pan=new JPanel();static JLabel label1 = new JLabel("用户");static JLabel label2 = new JLabel("密码");static JTextField textField1 = new JTextField();static JPasswordField password = new JPasswordField();static JButton button1 = new JButton("进入系统");static JRadioButton radioButton1=new JRadioButton("管理员",true);//“管理员”初始状态被选中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){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,"用户名或密码不能为空");}else{JOptionPane.showMessageDialog(null,"用户名或密码输入有误");}}if(radioButton2.isSelected())//学生{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(s,ce.getMessage());}try{Connection con = DriverManager.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,"您的输入有误");}//stmt.close();}catch (SQLException se){JOptionPane.showMessageDialog(s,se.getMessage());}}}}//interface.javaimport 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("删除信息");static JLabel label3 = new JLabel("请选择操作项");static JLabel label4 = new JLabel("学籍管理系统");static JButton button2 = new JButton("添加信息");static JButton button3 = new JButton("修改信息");static JButton button4 = new JButton("信息查询");static 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);this.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) {}}elseif(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){}}}}//tj.java 添加界面import javax.swing.*;import java.awt.*;import java.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(){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);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.getMessage());}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.showMessageDialog(s,se.getMessage());}}}}//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){JOptionPane.showMessageDialog(s,ce.getMessage());}try{Connection con = DriverManager.getConnection("jdbc:odbc:stu","sa","");Statement stmt = con.createStatement();ResultSet rs=stmt.executeQuery("select * from xinxi where 学号='"+textField1.getText()+"'");if(textField1.getText().trim().equals("")){JOptionPane.showMessageDialog(this,"学号不可为空!");}else if(rs.next()){String updateSql="update xinxi set 学号='"+textField1.getText()+"', 姓名='"+textField2.getText()+"',性别='"+textField7.getText()+"',出生日期='"+textField3.getText()+"',政治面貌='"+textField8.getText()+"',籍贯='"+textField4.getText()+"',系别='"+textField9.getText()+"',专业='"+textField5.getText()+ "'";try{stmt.executeQuery(updateSql);}catch(SQLException se){JOptionPane.showMessageDialog(null,"修改成功");}}}catch(SQLException se){JOptionPane.showMessageDialog(s,se.getMessage());}}}}//sc.java 删除界面import javax.swing.*;import java.awt.*;import java.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 con = DriverManager.getConnection("jdbc:odbc:stu","sa","");Statement stmt = con.createStatement();ResultSet rs=stmt.executeQuery("select * from xinxi where 学号='"+textField1.getText()+"'");if(textField1.getText().trim().equals("")){JOptionPane.showMessageDialog(this,"学号不可为空!");}else if(rs.next()){JOptionPane.showConfirmDialog(null,"确定要删除该信息嘛?\n删除的信息将不能恢复,继续?","删除确定",JOptionPane.OK_CANCEL_OPTION);//,JOption.QUESTION_MESSAGE)==0;stmt.execute("delete from xinxi where 学号='"+textField1.getText()+"'");JOptionPane.showMessageDialog(null,"删除信息成功!");this.dispose();}else JOptionPane.showMessageDialog(null,"无此学号对应信息","警告",JOptionPane.WARNING_MESSAGE);}catch(Exception ed){JOptionPane.showMessageDialog(s,ed.getMessage());}}}}//cx.java 查询界面import javax.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 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 con = DriverManager.getConnection("jdbc:odbc:stu","sa","");Statement stmt = con.createStatement();ResultSet rs=stmt.executeQuery("select * from xinxi where 学号='"+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("籍贯"));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运行程序。

相关文档
最新文档