学生信息管理系统java课程设计源代码

合集下载

学生管理系统JAVA课课程设计

学生管理系统JAVA课课程设计

学生管理系统JAVA课课程设计一、教学目标本课程的目标是让学生掌握学生管理系统的Java编程知识,能够运用Java语言实现一个简单的学生管理系统。

具体目标如下:1.知识目标:–理解Java语言的基本语法和数据结构。

–掌握Java中的控制结构和面向对象编程思想。

–了解Java中的文件操作和数据库连接。

2.技能目标:–能够使用Java编写简单的程序,实现学生的增删改查功能。

–能够使用Java连接数据库,实现对学生信息的持久化存储。

–能够使用Java的文件操作,读写学生数据。

3.情感态度价值观目标:–培养学生的编程兴趣,提高学生解决问题的能力。

–培养学生团队协作的精神,提高学生的沟通表达能力。

二、教学内容根据课程目标,本课程的教学内容主要包括以下几个部分:1.Java语言基础:包括基本语法、数据类型、变量、运算符等。

2.控制结构:包括条件语句、循环语句等。

3.面向对象编程:包括类、对象、继承、多态等。

4.文件操作:包括文件的读写、文件管理等。

5.数据库连接:包括JDBC的概念、数据库的连接与操作等。

6.学生管理系统的设计与实现:包括系统需求分析、系统设计、功能实现等。

三、教学方法为了达到课程目标,本课程将采用以下几种教学方法:1.讲授法:用于讲解Java语言基础、控制结构、面向对象编程等理论知识。

2.案例分析法:通过分析实际案例,让学生理解并掌握文件操作和数据库连接的方法。

3.实验法:让学生动手编写代码,实现学生管理系统,提高学生的实际操作能力。

4.小组讨论法:分组让学生讨论问题,培养学生的团队协作和沟通能力。

四、教学资源为了支持课程的顺利进行,我们将准备以下教学资源:1.教材:《Java编程思想》等。

2.参考书:《Java核心技术》、《Java Web开发》等。

3.多媒体资料:教学PPT、视频教程等。

4.实验设备:计算机、网络环境、数据库服务器等。

五、教学评估本课程的评估方式包括平时表现、作业和考试三个部分,以保证评估的客观性和公正性。

学生信息管理系统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学生管理系统大作业代码

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)

学生信息管理系统源代码(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.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;import java.awt.event.WindowEvent;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.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; //用于存放密码输入Choice c=null; //用于存放登录方式选择JButton jB1=null; //登陆按钮JButton jB2=null; //退出按钮String UserName=null; //存放用户输入的用户名String UserPassword=null; //存放用户输入的密码int UserLimit=-1; //存放用户选择登陆权限public LoginGUI(){super();this.log = new JFrame("学生学籍管理系统");this.jPanel1=new JPanel();this.jPanel2=new JPanel();this.jPanel3=new JPanel();jLabel1=new JLabel("用户名");jLabel2=new JLabel("密码");jLabel3=new JLabel("登录方式");jLabel4=new JLabel(new ImageIcon("image/login.jpg"));t1=new TextField();t2=new TextField();c=new Choice(); //创建一个登录方式下拉选择框c.add("学生登陆");c.add("管理员登陆");jB1=new JButton("登陆"); //创建登陆按钮jB2=new JButton("退出"); //创建退出按钮}public void login(){BorderLayout border=new BorderLayout();border.setVgap(15);border.setHgap(10);log.setLayout(border); //设置登陆主窗口布局管理器为BorderLayoutlog.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));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=new StudentGUI(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(erNa me)&&sel.getStudentAllPassword().get(i).equals(erPass word)){log.setVisible(false);ll.studentGo();}else if(i==sel.getStudentAllId().size()-1){JOptionPane.showMessageDialog(LoginGUI.this.log,"用户名密码错误");}}}else if(erLimit==1){AdminGUI admin=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(erNam e)&&sel.getAdminAllPassword().get(i).equals(erPasswor d)){log.setVisible(false);admin.adminGo();}else if(i==sel.getAdminAllId().size()-1){JOptionPane.showMessageDialog(LoginGUI.this.log,"用户名密码错误");}}}}});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(){@Overridepublic void windowClosing(WindowEvent e){System.exit(0);}});log.setVisible(true);}}3.AdminGUI.java/*管理员登陆图形界面*/package ms;import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.TextArea;import java.awt.TextField;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;public class AdminGUI{JDialog log=null;//管理员登陆主窗口JPanel jp1=null;//用于存放管理员登陆标签和jp5JPanel jp2=null;//用于存放查询修改增加删除按钮JPanel jp3=null;//用于存放信息块和jp5JPanel jp4=null;//用于存放修改插入删除按钮JPanel jp5=null;//用于存放请输入学号文本框JLabel jadminLog=null; //管理员登陆标签JLabel jLabel=null; //请输入学号标签TextField tf=null; //请输入学号文本框JButton jb1=null;//查询按钮JButton jb2=null;//修改按钮JButton jb3=null;//增加按钮JButton jb4=null;//删除按钮JButton jb5=null; //列出全部学生信息TextArea ta=null;//信息文本框JLabel jl=null; //用于站位String id=null; //用于保存用户输入查询学号TextField[] jtf = new T extField[9] ;JDialog jdialog=null;public AdminGUI(JFrame log){super();this.log = new JDialog(log,"管理员登陆",true);jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();jp5=new JPanel();jadminLog=new JLabel(new ImageIcon("image/admin.jpg"));jLabel=new JLabel("请输入学号");tf=new TextField();jb1=new JButton("查询");jb2=new JButton("修改");jb3=new JButton("增加");jb4=new JButton("删除");jb5=new JButton("列出全部学生信息");ta=new TextArea("点击查询按钮将在此显示查询信息");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(new GridLayout(1,2,200,200));jp5.add(jLabel);jp5.add(tf);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();AdminGUI.this.ta.setText("学号\t\t"+"姓名\t\t"+"性别\t\t"+"出生日期\t\t"+"民族\t\t"+"籍贯\t\t"+"专业\t\t"+"班级\t\t"+"联系电话\t\t"+"密码\t\t");AdminGUI.this.ta.append("\n"+student.getId()+"\t\t"+student.getNa me()+"\t\t"+student.getSex()+"\t\t"+student.getBornDate()+"\t\t"+student.getNationality()+"\t\t"+student.getNationality()+"\t\t"+stu dent.getMaj()+"\t"+student.getCla()+"\t\t"+student.getTelNum()+"\t\t"+student.getPassword()+"\n");}else{AdminGUI.this.ta.setText("查无此人");}}});jb5.addActionListener(new ActionListener(){@Overridepublic void actionPerformed(ActionEvent e){Select sel=new Select();sel.selectAllStudent();AdminGUI.this.ta.setText("学号\t\t"+"姓名\t\t"+"性别\t\t"+"出生日期\t\t"+"民族\t\t"+"籍贯\t\t"+"专业\t\t"+"班级\t\t"+"联系电话\t\t"+"密码\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\t"+student.getName() +"\t\t"+student.getSex()+"\t\t"+student.getBornDate()+"\t\t"+student.getNationality()+"\t\t"+student.getHometown()+"\t\t"+st udent.getMaj()+"\t"+student.getCla()+"\t\t"+student.getTelNum()+"\t\t"+student.getPa ssword()+"\n");}}});log.setSize(850,580);log.setLocationRelativeTo(null);log.setResizable(false);jb3.addActionListener(new ActionListener(){@Overridepublic void actionPerformed(ActionEvent e){jdialog=new JDialog(AdminGUI.this.log);String[] str=new String[]{"姓名","性别","出生日期","民族","籍贯","专业","班级","联系电话","密码"};JLabel[] jlabel=new JLabel[9];for(int i=0;i<9;i++){jlabel[i]=new JLabel(str[i]);jtf[i]=new TextField();}JPanel jpanel1=new JPanel();JPanel jpanel2=new JPanel();JButton jbutton1=new JButton("确定");JButton jbutton2=new JButton("取消");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){JOptionPane.showMessageDialog(AdminGUI.this.log,"添加成功");}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){JOptionPane.showMessageDialog(AdminGUI.this.log,"刪除成功");}elseJOptionPane.showMessageDialog(AdminGUI.this.log,"刪除失敗");}});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());Student student=sel.getStudent();if(student==null){JOptionPane.showMessageDialog(AdminGUI.this.log,"请检查输入的学号");}else{jdialog=new JDialog(AdminGUI.this.log);String[] str=new String[]{"姓名","性别","出生日期","民族","籍贯","专业","班级","联系电话","密码"};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]=new TextField(student.getSex());jtf[2]=new TextField(student.getBornDate());jtf[3]=new TextField(student.getNationality());jtf[4]=new TextField(student.getHometown());jtf[5]=new TextField(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();JButton jbutton1=new JButton("确定");JButton jbutton2=new JButton("取消");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(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){JOptionPane.showMessageDialog(AdminGUI.this.log,"更改成功");;}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);}}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; import java.awt.event.WindowEvent; import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;public class StudentGUI{JDialog log=null;//学生登入类主窗口JPanel jp1=null;//用于存放登入块JPanel jp2=null;//用于存放信息块JPanel jp3=null;//用于密码存放修改块JPanel jp4=null;//用于存放我的信息按钮JLabel jl1=null;//学生登入标签JLabel jl2=null;//学号标签JLabel jl3=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;//出生日期文本框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();this.log = new JDialog(log,"学生登入",true);jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();jl1=new JLabel(new ImageIcon("image/student.jpg"));jl2=new JLabel("学号:");jl3=new JLabel("学生姓名:");jl4=new JLabel("性别:");jl5=new JLabel("出生日期:");jl6=new JLabel("民族:");jl7=new JLabel("籍贯:");jl8=new JLabel("专业:");jl9=new JLabel("班级:");jl10=new JLabel("联系电话:");jl11=new JLabel("请输入新密码:");jb1=new JButton("我的信息");jb2=new JButton("密码修改");t1=new TextField();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);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(new GridLayout(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(){@Overridepublic 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());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){JOptionPane.showMessageDialog(StudentGUI.this.log,"修改成功");}}});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;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" ;// MySQL数据库的连接用户名public static final String DBUSER = "root" ;// MySQL数据库的连接密码public 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(){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(SQLException 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();}try{rs.close() ;stmt.close() ;conn.close() ; // 数据库关闭}catch(SQLException e){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(SQLException 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){e1.printStackTrace();}try{rs.close() ;stmt.close() ;conn.close() ; // 数据库关闭}catch(SQLException e){e.printStackTrace() ;}}public boolean selectStudent(String str){Connection conn = null ; // 数据库连接PreparedStatement pstmt = null ; // 数据库的操作对象ResultSet rs = null ; // 保存查询结果String sql = "select name,sex,bornDate,nationality,hometown,maj,cla,telNum,password "+ "from student where id=?";try{Class.forName(DBDRIVER) ; // 加载驱动程序}catch(ClassNotFoundException e){e.printStackTrace() ;}try{conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;}catch(SQLException 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();}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(SQLException e){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 * "+"from student";try{Class.forName(DBDRIVER) ; // 加载驱动程序}catch(ClassNotFoundException e){e.printStackTrace() ;}try{conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;}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(SQLException e){e.printStackTrace() ;}}}6.UpdateAndInsert.java/*修改&&插入类定义了修改和插入的所有方法*/package ms;import java.sql.Connection;import java.sql.DriverManager;import java.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 = "root" ;// MySQL数据库的连接密码public static final String DBPASS = "systemout" ;public boolean insertStudent (Student student){String name=student.getName();String sex=student.getSex();String bornDate=student.getBornDate();String nationality=student.getNationality();String hometown=student.getHometown();String maj=student.getMaj();String cla=student.getCla();String telNum=student.getTelNum();String password=student.getPassword();Connection conn = null ; // 数据库连接Statement stmt = null ; // 数据库操作try{Class.forName(DBDRIVER) ;} catch (ClassNotFoundException e){// TODO Auto-generated catch blocke.printStackTrace();} // 加载驱动程序String sql = "INSERT INTO student(name,sex,bornDate,nationality,hometown,maj,cla,telNum,passw ord) "+" VALUES('"+name+"','"+sex+"','"+bornDate+"','"+nationality+"','"+hometown+"' ,'"+maj+"','"+cla+"','"+telNum+"','"+password+"')";try{conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;} catch (SQLException e){// TODO Auto-generated catch blocke.printStackTrace();}try{stmt = conn.createStatement() ;} catch (SQLException e){// TODO Auto-generated catch blocke.printStackTrace();} // 实例化Statement对象try{stmt.executeUpdate(sql) ;} catch (SQLException e){// TODO Auto-generated catch blocke.printStackTrace();} // 执行数据库更新操作try{stmt.close() ; // 关闭操作conn.close() ;} catch (SQLException e){// TODO Auto-generated catch blocke.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();String sex=student.getSex();String bornDate=student.getBornDate();String nationality=student.getNationality();String hometown =student.getHometown();String maj=student.getMaj();String cla=student.getCla();String telNum=student.getTelNum();String password=student.getPassword();String sql="UPDATE student SET name='"+name+"',sex='"+sex+"',bornDate='"+bornDate+"',nationality ='"+nationality+"',hometown='"+hometown+"',maj='"+maj+"',cla='"+c la+"',telNum='"+telNum+"',password='"+password+"' WHERE id="+student.getId() ;try{conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;} catch (SQLException e1){// TODO Auto-generated catch blocke1.printStackTrace();}try{stmt = conn.createStatement() ;} catch (SQLException e){// TODO Auto-generated catch blocke.printStackTrace();} // 实例化Statement对象try{stmt.executeUpdate(sql) ;} catch (SQLException e){// TODO Auto-generated catch blocke.printStackTrace();} // 执行数据库更新操作try{stmt.close() ; // 关闭操作conn.close() ; // 数据库关闭} catch (SQLException e){// TODO Auto-generated catch blocke.printStackTrace();}return true;}。

学生信息管理系统源代码

学生信息管理系统源代码

学生信息管理系统源代码import java.io.*;class StuInfo {public String name;public int number;public String sex;public String age;public String bir;public String email;public String addr;public String tel;public String getName() {return name;}public void setName(String name) { = name;}public int getNumber() {return number;}public void setNumber(int number) {this.number = number;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public String getAge() {return age;}public void setAge(String age) {this.age = age;}public String getBir() {return bir;}public void setBir(String bir) {this.bir = bir;}public String getEmail() {return email;}public void setEmail(String email ) { this.email = email;}public String getAddr() {return addr;}public void setAddr(String addr) {this.addr = addr;}public String getTel() {return tel;}public void setTel(String tel) {this.tel = tel;}}public class Student {private static PrintStream out = System.out;private static String filename = "Stu.txt";private static int total = 0;private static int rt = 0;//recyle lengthprivate StuInfo[] stuInfos;private StuInfo[] recycle;BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));//创建缓冲流public Student(){stuInfos = new StuInfo[11];}public void 信息录入(){BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));try{System.out.print("\n请输入学生信息(以0结束)\n");System.out.print("学号:\n");StuInfo stu = new StuInfo();stu.setNumber(Integer.parseInt(buf.readLine()));while(stu.getNumber()!=0) {System.out.print("姓名:\n\n");stu.setName(buf.readLine());System.out.print("性别:\n\n");stu.setSex(buf.readLine());System.out.print("年龄:\n\n");stu.setAge (buf.readLine());System.out.print("生日:\n\n");stu.setBir(buf.readLine());System.out.print("邮箱:\n\n");stu.setEmail(buf.readLine());System.out.print("地址:\n\n");stu.setAddr(buf.readLine());System.out.print("电话:\n\n");stu.setTel(buf.readLine());//添加其他输入信息stuInfos[total]=stu;total++;stu = new StuInfo();System.out.print("\n请输入下一个学生信息(以0结束)\n");System.out.print("姓名:\n");stu.setName(buf.readLine());}}catch(Exception e){out.print(e);}}public void 保存数据(){try{FileWriter fwr=new FileWriter(filename);BufferedWriter fw = new BufferedWriter(fwr);fw.write(total+"\r\n");for(int k=0;k<total;k++){//保存学生信息fw.write(stuInfos[k].getNumber()+"\r\n");fw.write(stuInfos[k].getName()+"\r\n");fw.write(stuInfos[k].getSex()+"\r\n");fw.write(stuInfos[k].getAge()+"\r\n");fw.write(stuInfos[k].getBir()+"\r\n");fw.write(stuInfos[k].getEmail()+"\r\n");fw.write(stuInfos[k].getAddr()+"\r\n");fw.write(stuInfos[k].getTel()+"\r\n");}fw.write(rt+"\r\n");for(int k=0;k<rt;k++){//保存回收站信息fw.write(recycle[k].getNumber()+"\r\n");fw.write(recycle[k].getName()+"\r\n");fw.write(recycle[k].getSex()+"\r\n");fw.write(recycle[k].getAge()+"\r\n");fw.write(recycle[k].getBir()+"\r\n");fw.write(recycle[k].getEmail()+"\r\n");fw.write(recycle[k].getAddr()+"\r\n");fw.write(recycle[k].getTel()+"\r\n");}fw.flush();fw.close();fwr.close();System.out.println("\n已保存数据!");}catch(Exception e){out.print(e);}}public void 读取数据(){try{FileReader fr = new FileReader(filename);BufferedReader bfr = new BufferedReader(fr); String buff = bfr.readLine();if(buff != null) {total = Integer.parseInt(buff);}else{total = 0;}StuInfo stu;for(int i=0; i<total;i++) {stu = new StuInfo();stu.setNumber(Integer.parseInt(bfr.readLine())); stu.setName(bfr.readLine());stu.setSex(bfr.readLine());stu.setAge(bfr.readLine());stu.setBir(bfr.readLine());stu.setEmail(bfr.readLine());stu.setAddr(bfr.readLine());stu.setTel(bfr.readLine());stuInfos[i]=stu;}buff = bfr.readLine();if(buff!= null) {rt = Integer.parseInt(buff);}else{rt = 0;}for(int i=0; i<rt;i++) {stu = new StuInfo();stu.setNumber(Integer.parseInt(bfr.readLine()));stu.setName(bfr.readLine());stu.setSex(bfr.readLine());stu.setAge(bfr.readLine());stu.setBir(bfr.readLine());stu.setEmail(bfr.readLine());stu.setAddr(bfr.readLine());stu.setTel(bfr.readLine());//补全recycle[i]=stu;}// bfr.flush();bfr.close();fr.close();System.out.println("读取成功");}catch(Exception e){out.print(e);}}public void 显示学生(StuInfo[] stus,int length){ try{out.println("----------");for(int i=0;i<length;i++){out.println("学号:"+stus[i].getNumber());out.println("姓名:"+stus[i].getName());out.println("性别:"+stus[i].getSex());out.println("年龄:"+stus[i].getAge());out.println("生日:"+stus[i].getBir());out.println("邮箱:"+stus[i].getEmail());out.println("地址:"+stus[i].getAddr());out.println("电话:"+stus[i].getTel());//输出其他内容.....out.println("----------");}System.out.println("请按任意键继续");buf.read();//}catch(Exception e){out.print(e);}}public void 姓名查询(String name){StuInfo[] result = new StuInfo[11];int r = 0;for(int i=0;i<total;i++){if(stuInfos[i].getName().equals(name)){result[r]=stuInfos[i];r++;}}if(r==0){System.out.print("查找不到该学生!");//提示找不到学生return;}else{显示学生(result, r);}}public void 学号查询(String number ){StuInfo[] result = new StuInfo[11];int r = 0;for(int i=0;i<total;i++){if(Integer.toString(stuInfos[i].getNumber()).equals(number)){result[r]=stuInfos[i];r++;//补全}}if(r==0){System.out.print("查找不到该学生!");//提示找不到学生}else{显示学生(result, r);}}public void 查找菜单(){//全字匹配int choice;try{do{System.out.println("查找界面");//System.out.println("1:按姓名查询");System.out.println("2:按学号查询");System.out.println("0:返回上级");BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));choice = Integer.parseInt(buf.readLine());switch(choice){case 1:System.out.println("请输入姓名");//获得输入的姓名String name = buf.readLine();姓名查询(name);break;case 2:System.out.println("请输入学号");String number = buf.readLine();学号查询(number);//获得输入的学号break;default:System.out.println("对不起,出现异常!");//异常:7}}while(choice!=0);}catch(Exception e){out.print(e);}}public boolean 修改学生(int number) {boolean flag = false;try{for(int i=0;i<total;i++){if(stuInfos[i].getNumber()==number) {BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));StuInfo stu = new StuInfo();System.out.print("\n请输入学生信息\n");System.out.print("姓名:\n\n");stu.setName(buf.readLine());System.out.print("性别:\n\n");stu.setSex(buf.readLine());System.out.print("年龄:\n\n");stu.setAge (buf.readLine());System.out.print("生日:\n\n");stu.setBir(buf.readLine());System.out.print("邮箱:\n\n");stu.setEmail(buf.readLine());System.out.print("地址:\n\n");stu.setAddr(buf.readLine());System.out.print("电话:\n\n");stu.setTel(buf.readLine());stu.setNumber(number);stuInfos[i]=stu;System.out.print("修改完成啦!");//提示修改完成break;}}}catch(Exception e){out.print(e);}return flag;}public boolean 删除学生(int number){boolean flag = false;for(int i=0;i<total;i++){if(stuInfos[i].getNumber()==number){if(rt==0){recycle = new StuInfo[101];}recycle[rt]=stuInfos[i];for(;i<total-1;i++){stuInfos[i]=stuInfos[i+1];}total--;flag=true;break;}}return flag;}public void 删除页面(){System.out.print("删除页面");//请输入要删除的学号try{int choice;BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));System.out.println("1:学生信息修改");System.out.println("2:学生信息删除");System.out.println("请输入您的选择(1--2)");//...choice = Integer.parseInt(buf.readLine());switch(choice){case 1:System.out.println("请输入要修改的学号:");choice = Integer.parseInt(buf.readLine());修改学生(choice);break;case 2:System.out.println("请输入要删除的学号:");choice = Integer.parseInt(buf.readLine());删除学生(choice);break;//补充}/*if(删除学生(choice)){System.out.print("删除成功!");//删除成功}else{System.out.print("删除失败!");//删除失败}*/}catch(Exception e){out.print(e);}}public void showMenu() {try{int choice;do{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("6:学生信息读取");System.out.println("0:退出系统");System.out.println("请输入您的选择(0--6)");BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));choice = Integer.parseInt(buf.readLine());switch(choice){case 1:信息录入();//break;case 2://补全方法调用显示学生(stuInfos, total);break;case 3:查找菜单();break;case 4:删除页面();break;case 5:保存数据();break;case 6:读取数据();break;default:System.out.print("出现异常!"); //异常:7}}while(choice!=0);}catch(Exception e){System.out.println(e);}// TODO 自动生成的方法存根}public static void main(String[] args) {Student student = new Student();student.showMenu();}}. ..。

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

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

系统源代码一、登录界面代码using System;using System.Data;using System。

Configuration;using System。

Collections;using System.Web;using System.Web。

Security;using System。

Web.UI;using System。

Web。

UI。

WebControls;using System.Web。

UI.WebControls。

WebParts;using System。

Web.UI.HtmlControls;using System.Data。

SqlClient;public partial class login :System.Web。

UI。

Page{protected void txtid_Click(object sender,EventArgs e){txtid.Text = ”";txtpassword。

Text = ””;}protected void Button1_Click(object sender, EventArgs e){string strconn = ConfigurationManager。

AppSettings[”connStr”];SqlConnection conn = new SqlConnection(strconn);conn。

Open();DataSet ds=new DataSet ();SqlDataAdapter da = new SqlDataAdapter("select * from users where userid=’" + txtid。

Text + "' and userpwd=’” + txtpassword.Text + ”’", conn);da.Fill(ds);if (ds。

java代码设计文档

java代码设计文档

java代码设计文档Java代码设计文档是用于记录和描述Java程序的设计思路、功能模块、类和方法的用途以及实现细节的文档。

它旨在帮助开发人员和其他相关人员了解和理解Java程序的设计和实现过程。

本文将以一个简单的学生管理系统为例,展示如何编写Java代码设计文档。

# 1. 引言本文档旨在描述学生管理系统的设计和实现细节。

该系统用于管理学生的基本信息、课程信息和成绩信息。

# 2. 系统概述学生管理系统是一个基于Java的桌面应用程序,用于管理学生信息。

它提供了以下功能:- 添加学生信息:包括姓名、学号、性别、年龄等基本信息。

- 添加课程信息:包括课程名称、学分、教师等信息。

- 添加成绩信息:将学生与课程关联,并录入学生的成绩。

- 查询学生信息:根据学号或姓名查询学生的基本信息、课程信息和成绩信息。

- 修改学生信息:可以修改学生的基本信息、课程信息和成绩信息。

- 删除学生信息:可以删除学生的基本信息、课程信息和成绩信息。

# 3. 系统结构学生管理系统由以下几个模块组成:- 学生信息模块:用于管理学生的基本信息。

- 课程信息模块:用于管理课程的基本信息。

- 成绩信息模块:用于管理学生的成绩信息。

- 数据库模块:用于连接和操作数据库,存储和读取学生、课程和成绩信息。

# 4. 类设计## 4.1 学生类学生类表示学生的基本信息,包括姓名、学号、性别和年龄等属性。

它具有以下方法:- 构造方法:用于创建学生对象,初始化学生的基本信息。

- getter和setter方法:用于获取和设置学生的属性值。

## 4.2 课程类课程类表示课程的基本信息,包括课程名称、学分和教师等属性。

它具有以下方法:- 构造方法:用于创建课程对象,初始化课程的基本信息。

- getter和setter方法:用于获取和设置课程的属性值。

## 4.3 成绩类成绩类表示学生的成绩信息,包括学生、课程和成绩等属性。

它具有以下方法:- 构造方法:用于创建成绩对象,初始化成绩的基本信息。

[工学]学生信息管理系统完整源码

[工学]学生信息管理系统完整源码

学生信息管理系统完整源代码注:本系统采用C/S结构,运用Java GUI知识编写,数据库为SQL SERVER 2005,没有采用典型的三级框架结构,所以代码有冗余,仅供参考。

一、数据表及数据源首先创建数据库,包含数据表如下:数据库创建完成后,新建一个名为SIMS的数据源,不会建数据源的同学可以在去搜索创建数据源的详细步骤,这里的数据名称一定要为SIMS,否则在以后程序连接数据库的语句中会出现错误。

二、操作演示三、代码部分创建Java工程,创建名称为SIMS的包,一下Java类均包含在一个包内。

1.登录界面package SIMS;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;import java.text.SimpleDateFormat;import java.util.*;import java.util.Date;public class login extends JFrame implements ActionListener{String userID; //保留用户输入IDString password; //保留用户输入passwordJLabel jlID=new JLabel("用户ID:"); //使用文本创建标签对象 JLabel jlPwd=new JLabel("密码:");JTextField jtID=new JTextField(); //创建ID输入框JPasswordField jpPwd=new JPasswordField(); //创建密码输入框ButtonGroup bg=new ButtonGroup(); //创建ButtonGroup组件对象JPanel jp=new JPanel(); //创建Panel容器JLabel jl=new JLabel();JRadioButton jrb1=new JRadioButton("管理员");JRadioButton jrb2=new JRadioButton("教师");JRadioButton jrb3=new JRadioButton("学生",true);JButton jb1=new JButton("登录");JButton jb2=new JButton("重置");public login(){this.setLayout(null); //设置窗口布局管理器this.setTitle("学生信息管理系统"); //设置窗口标题this.setBounds(200,150,500,300); //设置主窗体位置大小和可见性this.setVisible(true); //设置窗口的可见性this.setResizable(false);jlID.setBounds(150,60,100,20); //设置ID框属性jtID.setBounds(220,60,100,20); //设置ID输入框属性jlPwd.setBounds(150,90,100,20); //设置密码框属性jpPwd.setBounds(220,90,100,20); //设置密码输入框属性jp.setBounds(35,120,400,250); //设置JPanel容器属性jb1.setBounds(160,170,60,20); //设置登录按钮属性jb2.setBounds(250,170,60,20); //设置取消按钮属性jb1.addActionListener(this); //设置登录按钮监听器jb2.addActionListener(this); //设置取消按钮监听器jl.setBounds(340,75,130,20); //设置提示框属性bg.add(jrb1); //将所有空间加入窗体bg.add(jrb2);bg.add(jrb3);this.add(jlID);this.add(jlPwd);this.add(jtID);this.add(jpPwd);this.add(jb1);this.add(jb2);this.add(jl);jp.add(jrb1);jp.add(jrb2);jp.add(jrb3);this.add(jp);centerShell(this);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}private void centerShell(JFrame shell) //窗口在屏幕中间显示{//得到屏幕的宽度和高度int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;//得到Shell窗口的宽度和高度int shellHeight = shell.getBounds().height;int shellWidth = shell.getBounds().width;//如果窗口大小超过屏幕大小,让窗口与屏幕等大if(shellHeight > screenHeight)shellHeight = screenHeight;if(shellWidth > screenWidth)shellWidth = screenWidth;//让窗口在屏幕中间显示shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) );}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(userID);}return false;}public void actionPerformed(ActionEvent e){userID=jtID.getText(); //获取用户输入IDpassword=jpPwd.getText(); //获取用户输入密码if(e.getSource()==jb1){ //处理登录事件if(userID.equals("") || password.equals("")){jl.setFont(new Font("red",Font.BOLD,12)); //设置提示字体jl.setForeground(Color.red);jl.setText("请输入用户ID和密码");}else{Connection con=null;try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"","");//获取连接字符串Statement stat=con.createStatement();if(jrb1.isSelected())//如果登录选中的管理员{ResultSet rs=stat.executeQuery("select * from Admin"); //判断输入用户名是否存在int flag=0;while(rs.next()){if(rs.getString(1).equals(userID)){flag=1;break;}}if(flag==0){jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("用户ID不存在");}if(flag==1){ResultSet rss=stat.executeQuery("selectAdmin_Pwd,Admin_Name from Admin where Admin_ID='"+userID+"'");//从表Admin获取信息while(rss.next()){String str=rss.getString(1);if(str.equals(password)){new admin(rss.getString(2));//创建admin窗口this.dispose(); //释放窗体}else{jl.setFont(new Font("red",Font.BOLD,12)); //设置提示字体jl.setForeground(Color.red);jl.setText("密码错误");}}}}else if(jrb2.isSelected()){ResultSet rs=stat.executeQuery("select * from Teacher_Info"); //判断输入用户名是否存在int flag=0;while(rs.next()){if(rs.getString(1).equals(userID)){flag=1;break;}}if(flag==0){jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("用户ID不存在");}if(flag==1){ResultSet rss=stat.executeQuery("selectTea_Pwd,Tea_Names from Teacher_Info where Tea_ID='"+userID+"'");//从表Teacher_Info获取信息while(rss.next()){String str=rss.getString(1);if(str.equals(password)){new teacher(rss.getString(2),userID);//创建admin窗口this.dispose(); //释放窗体}else{jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("密码错误");}}}}else if(jrb3.isSelected()){ResultSet rs=stat.executeQuery("select * from Student_Info"); //判断输入用户名是否存在int flag=0;while(rs.next()){if(rs.getString(1).equals(userID)){flag=1;break;}}if(flag==0){jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("用户ID不存在");}if(flag==1){ResultSet rsss=stat.executeQuery("selectStu_Pwd,Stu_Name from Student_Info where Stu_ID='"+userID+"'");//从表Student_Info获取信息while(rsss.next()){String str=rsss.getString(1);if(str.equals(password)){new student(rsss.getString(2),userID);//创建admin窗口this.dispose(); //释放窗体}else{jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("密码错误");}}}}}catch(Exception ex){ex.getStackTrace();}finally{try{con.close();}catch(Exception exc){exc.printStackTrace();}}}}else if(e.getSource()==jb2){ //处理登录事件jtID.setText("");jpPwd.setText("");jrb3.setSelected(true);jl.setText("");}}public static void main(String[] args){new login();}}2.添加课程package SIMS;import javax.swing.*;import java.sql.*;import java.awt.*;import java.awt.event.*;public class add_course extends JFrame implements ActionListener{ static add_course ss;String courseID=""; //课程名String coursename=""; //课程名String count=""; //课时JLabel warning=new JLabel(); //输入信息提示框JLabel title=new JLabel();JLabel note1=new JLabel("*");JLabel note2=new JLabel("*");JLabel jlcourseID=new JLabel("课程号:"); //使用文本框创建标签对象JLabel jlcoursename=new JLabel("课程名:");JLabel jlcount=new JLabel("课时:");JTextField jtcourseID=new JTextField(); //创建文本框对象JTextField jtcoursename=new JTextField();JTextField jtcount=new JTextField();JButton submit=new JButton("添加"); //创建按钮对象JButton reset=new JButton("重置");public add_course(){ //添加教师账号信息this.setTitle("添加课程信息"); //设置窗口标题this.setLayout(null); //设置窗口布局管理器this.add(jlcourseID); //将控件添加到窗体this.add(title);this.add(jlcoursename);this.add(jlcount);this.add(jtcourseID);this.add(jtcoursename);this.add(jtcount);this.add(note1);this.add(note2);this.add(submit);this.add(reset);this.add(warning);title.setFont(new Font("red",Font.BOLD,15)); //设置提示字体title.setForeground(Color.red);note1.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note1.setForeground(Color.red);note2.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note2.setForeground(Color.red);warning.setFont(new Font("red",Font.BOLD,12)); //设置提示字体warning.setForeground(Color.red);title.setText("添加课程信息"); //设置控件及窗体位置大小title.setBounds(222,20,150,20);jlcourseID.setBounds(180,80,100,20);jlcoursename.setBounds(180,140,100,20);jlcount.setBounds(180,200,100,20);jtcourseID.setBounds(250,80,140,20);jtcoursename.setBounds(250,140,140,20);jtcount.setBounds(250,200,140,20);note1.setBounds(400,80,140,20);note2.setBounds(400,140,140,20);submit.setBounds(200,270,60,20);reset.setBounds(300,270,60,20);warning.setBounds(420,140,150,20); //设置提示框位置大小submit.addActionListener(this); //添加监听器reset.addActionListener(this);this.setSize(600,400); //设置窗体大小centerShell(this); //设置窗口位置在屏幕中央this.setResizable(false); //设置窗体不可变大小this.setVisible(true); //设置窗口可见性this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(courseID);}return false;}public void actionPerformed(ActionEvent e){courseID=jtcourseID.getText(); //获取用户输入内容coursename=jtcoursename.getText();count=jtcount.getText();int temp=0,flag=0;Connection con=null;if(e.getSource()==submit){ //判断是否已输入必填信息if(courseID.equals("") || coursename.equals("")){warning.setText("请输入必填信息");}else{try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"",""); //获取连接字符串Statement stat=con.createStatement();ResultSet rs=stat.executeQuery("select Course_ID from Course");while(rs.next()){if(rs.getString(1).equals(courseID)){warning.setText("课程ID已存在");flag=1; //判断用户名唯一break;}}if(flag!=1){if(!count.equals("")){temp=stat.executeUpdate("insert intoCourse(Course_ID,Course_Name,Course_Count)values('"+courseID+"','"+coursename+"','"+count+"')");}else{temp=stat.executeUpdate("insert intoCourse(Course_ID,Course_Name) values('"+courseID+"','"+coursename+"')");}}if(temp==1){JOptionPane.showMessageDialog(ss,"添加成功");warning.setText("");}else{JOptionPane.showMessageDialog(ss,"添加失败");}}catch(Exception ex){ex.getStackTrace();}}}else if(e.getSource()==reset){warning.setText("");jtcourseID.setT ext("");jtcoursename.setText("");jtcount.setText("");}}private void centerShell(JFrame shell) //窗口在屏幕中间显示{//得到屏幕的宽度和高度int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;//得到Shell窗口的宽度和高度int shellHeight = shell.getBounds().height;int shellWidth = shell.getBounds().width;//如果窗口大小超过屏幕大小,让窗口与屏幕等大if(shellHeight > screenHeight)shellHeight = screenHeight;if(shellWidth > screenWidth)shellWidth = screenWidth;//让窗口在屏幕中间显示shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2));}}3.添加学生package SIMS;import javax.swing.*;import java.sql.*;import java.awt.*;import java.awt.event.*;public class add_student extends JFrame implements ActionListener{static add_teacher ss;String userID=""; //用户名String pwd1=""; //密码String pwd2=""; //确认密码String getsdept=""; //院系String name=""; //姓名JLabel warning=new JLabel(); //输入信息提示框JLabel title=new JLabel();JLabel note1=new JLabel("*");JLabel note2=new JLabel("*");JLabel note3=new JLabel("*");JLabel jlID=new JLabel("学号:"); //创建文本框对象 JLabel jlName=new JLabel("姓名:");JLabel jlPwd=new JLabel("密码:");JLabel jlPwd2=new JLabel("确认密码:");JLabel sdept=new JLabel("学院:");JTextField jtID=new JTextField();JTextField jtName=new JTextField();JPasswordField jtPwd=new JPasswordField ();JPasswordField jtPwd2=new JPasswordField ();JTextField jtsdept=new JTextField();JButton submit=new JButton("添加"); //创建按钮对象JButton reset=new JButton("重置");public add_student(){this.setTitle("添加学生账号信息"); //设置窗口标题this.setLayout(null); //设置窗口布局管理器this.add(jlID); //将控件添加到窗体this.add(title);this.add(jlName);this.add(jlPwd);this.add(jlPwd2);this.add(sdept);this.add(jtID);this.add(jtName);this.add(jtPwd);this.add(jtPwd2);this.add(jtsdept);this.add(note1);this.add(note2);this.add(note3);this.add(submit);this.add(reset);this.add(warning);title.setFont(new Font("red",Font.BOLD,15)); //设置提示字体title.setForeground(Color.red);note1.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note1.setForeground(Color.red);note2.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note2.setForeground(Color.red);note3.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note3.setForeground(Color.red);warning.setFont(new Font("red",Font.BOLD,12)); //设置提示字体warning.setForeground(Color.red);title.setText("添加学生账号信息");title.setBounds(222,20,150,20);jlID.setBounds(180,60,100,20);jlName.setBounds(180,100,100,20);jlPwd.setBounds(180,140,100,20);jlPwd2.setBounds(180,180,100,20);sdept.setBounds(180,220,100,20);jtID.setBounds(250,60,140,20);jtName.setBounds(250,100,140,20);jtPwd.setBounds(250,140,140,20);jtPwd2.setBounds(250,180,140,20);jtsdept.setBounds(250,220,140,20);note1.setBounds(400,60,140,20);note2.setBounds(400,140,140,20);note3.setBounds(400,180,140,20);submit.setBounds(200,270,60,20);reset.setBounds(300,270,60,20);warning.setBounds(420,100,150,20);submit.addActionListener(this);reset.addActionListener(this);this.setSize(600,400);centerShell(this);this.setVisible(true);this.setResizable(false); //设置窗体不可变大小this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(pwd1);}return false;}public void actionPerformed(ActionEvent e){userID=jtID.getText(); //获取用户输入内容pwd1=jtPwd.getText();pwd2=jtPwd2.getText();getsdept=jtsdept.getText();name=jtName.getText();int temp=0,flag=0;Connection con=null;if(e.getSource()==submit){if(userID.equals("") || pwd1.equals("") || pwd2.equals("")){ //判断是否已输入必填信息warning.setText("请输入必填信息");}else if(!pwd1.equals(pwd2)){ //判断两次输入密码是否相同warning.setText("两次输入密码不相同");}else{try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"",""); //获取连接字符串Statement stat=con.createStatement();ResultSet rs=stat.executeQuery("select Stu_ID from Student_Info");while(rs.next()){if(rs.getString(1).equals(userID)){warning.setText("用户ID已存在");flag=1; //判断用户名唯一break;}}if(flag!=1){if(!name.equals("") && !getsdept.equals("")){temp=stat.executeUpdate("insert intoStudent_Info(Stu_ID,Stu_Name,Stu_Pwd,Depart)values('"+userID+"','"+name+"','"+pwd1+"','"+getsdept+"')");}else if(!name.equals("") && getsdept.equals("")){temp=stat.executeUpdate("insert intoStudent_Info(Stu_ID,Stu_Name,Stu_Pwd) values('"+userID+"','"+name+"','"+pwd1+"')");}else if(name.equals("") && !getsdept.equals("")){temp=stat.executeUpdate("insert intoStudent_Info(Stu_ID,Stu_Pwd,Depart) values('"+userID+"','"+pwd1+"','"+getsdept+"')");}else{temp=stat.executeUpdate("insert intoStudent_Info(Stu_ID,Stu_Pwd) values('"+userID+"','"+pwd1+"')");}}if(temp==1){JOptionPane.showMessageDialog(ss,"添加成功");}else{JOptionPane.showMessageDialog(ss,"添加失败");}}catch(Exception ex){ex.getStackTrace();}}}else if(e.getSource()==reset){ //重置所有控件warning.setText("");jtID.setText("");jtName.setText("");jtPwd.setText("");jtPwd2.setText("");jtsdept.setText("");}}private void centerShell(JFrame shell) //窗口在屏幕中间显示{//得到屏幕的宽度和高度int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;//得到Shell窗口的宽度和高度int shellHeight = shell.getBounds().height;int shellWidth = shell.getBounds().width;//如果窗口大小超过屏幕大小,让窗口与屏幕等大if(shellHeight > screenHeight)shellHeight = screenHeight;if(shellWidth > screenWidth)shellWidth = screenWidth;//让窗口在屏幕中间显示shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2));}//public static void main(String args[]){// new add_student();//}}4.添加教师package SIMS;import javax.swing.*;import java.sql.*;import java.awt.*;import java.awt.event.*;public class add_teacher extends JFrame implements ActionListener{static add_teacher ss;String userID=""; //用户名String pwd1=""; //密码String pwd2=""; //确认密码String getsdept=""; //院系String name=""; //姓名JLabel warning=new JLabel(); //输入信息提示框JLabel title=new JLabel();JLabel note1=new JLabel("*");JLabel note2=new JLabel("*");JLabel note3=new JLabel("*");JLabel jlID=new JLabel("教工号:"); //使用文本框创建标签对象 JLabel jlName=new JLabel("姓名:");JLabel jlPwd=new JLabel("密码:");JLabel jlPwd2=new JLabel("确认密码:");JLabel sdept=new JLabel("学院:");JTextField jtID=new JTextField(); //创建文本框对象JTextField jtName=new JTextField();JPasswordField jtPwd=new JPasswordField ();JPasswordField jtPwd2=new JPasswordField ();JTextField jtsdept=new JTextField();JButton submit=new JButton("添加"); //创建按钮对象JButton reset=new JButton("重置");public add_teacher(){ //添加教师账号信息this.setTitle("添加教师账号信息"); //设置窗口标题this.setLayout(null); //设置窗口布局管理器this.add(jlID); //将控件添加到窗体this.add(title);this.add(jlName);this.add(jlPwd);this.add(jlPwd2);this.add(sdept);this.add(jtID);this.add(jtName);this.add(jtPwd);this.add(jtPwd2);this.add(jtsdept);this.add(note1);this.add(note2);this.add(note3);this.add(submit);this.add(reset);this.add(warning);title.setFont(new Font("red",Font.BOLD,15)); //设置提示字体title.setForeground(Color.red);note1.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note1.setForeground(Color.red);note2.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note2.setForeground(Color.red);note3.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note3.setForeground(Color.red);warning.setFont(new Font("red",Font.BOLD,12)); //设置提示字体warning.setForeground(Color.red);title.setText("添加教师账号信息"); //设置控件及窗体位置大小title.setBounds(222,20,150,20);jlID.setBounds(180,60,100,20);jlName.setBounds(180,100,100,20);jlPwd.setBounds(180,140,100,20);jlPwd2.setBounds(180,180,100,20);sdept.setBounds(180,220,100,20);jtID.setBounds(250,60,140,20);jtName.setBounds(250,100,140,20);jtPwd.setBounds(250,140,140,20);jtPwd2.setBounds(250,180,140,20);jtsdept.setBounds(250,220,140,20);note1.setBounds(400,60,140,20);note2.setBounds(400,140,140,20);note3.setBounds(400,180,140,20);submit.setBounds(200,270,60,20);reset.setBounds(300,270,60,20);warning.setBounds(420,100,150,20); //设置提示框位置大小submit.addActionListener(this); //添加监听器reset.addActionListener(this);this.setSize(600,400); //设置窗体大小centerShell(this); //设置窗口位置在屏幕中央this.setResizable(false); //设置窗体不可变大小this.setVisible(true); //设置窗口可见性this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(pwd1);}return false;}public void actionPerformed(ActionEvent e){userID=jtID.getText(); //获取用户输入内容pwd1=jtPwd.getText();pwd2=jtPwd2.getText();getsdept=jtsdept.getText();name=jtName.getText();int temp=0,flag=0;Connection con=null;if(e.getSource()==submit){ //判断是否已输入必填信息if(userID.equals("") || pwd1.equals("") || pwd2.equals("")){warning.setText("请输入必填信息");}else if(!pwd1.equals(pwd2)){ //判断两次输入密码是否一致warning.setText("两次输入密码不相同");}else{try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"",""); //获取连接字符串Statement stat=con.createStatement();ResultSet rs=stat.executeQuery("select Tea_ID from Teacher_Info");while(rs.next()){if(rs.getString(1).equals(userID)){warning.setText("用户ID已存在");flag=1; //判断用户名唯一break;}}if(flag!=1){if(!name.equals("") && !getsdept.equals("")){temp=stat.executeUpdate("insert intoTeacher_Info(Tea_ID,Tea_Names,T ea_Pwd,Depart)values('"+userID+"','"+name+"','"+pwd1+"','"+getsdept+"')");}else if(!name.equals("") && getsdept.equals("")){temp=stat.executeUpdate("insert intoTeacher_Info(Tea_ID,Tea_Names,T ea_Pwd)values('"+userID+"','"+name+"','"+pwd1+"')");}else if(name.equals("") && !getsdept.equals("")){temp=stat.executeUpdate("insert intoTeacher_Info(Tea_ID,Tea_Pwd,Depart) values('"+userID+"','"+pwd1+"','"+getsdept+"')");}else{temp=stat.executeUpdate("insert intoTeacher_Info(Tea_ID,Tea_Pwd) values('"+userID+"','"+pwd1+"')");}}if(temp==1){JOptionPane.showMessageDialog(ss,"添加成功");}else{JOptionPane.showMessageDialog(ss,"添加失败");}}catch(Exception ex){ex.getStackTrace();}}}else if(e.getSource()==reset){warning.setText("");jtID.setText("");jtName.setText("");jtPwd.setText("");jtPwd2.setText("");jtsdept.setText("");}}private void centerShell(JFrame shell) //窗口在屏幕中间显示{//得到屏幕的宽度和高度int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;//得到Shell窗口的宽度和高度int shellHeight = shell.getBounds().height;int shellWidth = shell.getBounds().width;//如果窗口大小超过屏幕大小,让窗口与屏幕等大if(shellHeight > screenHeight)shellHeight = screenHeight;if(shellWidth > screenWidth)shellWidth = screenWidth;//让窗口在屏幕中间显示shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2));}// public static void main(String[] args){// new add_teacher();// }}5.添加授课信息package SIMS;import javax.swing.*;import java.sql.*;import java.awt.*;import java.awt.event.*;public class add_tc extends JFrame implements ActionListener{static add_tc ss;String courseID=""; //课程名String teachername=""; //课程名JLabel warning=new JLabel(); //输入信息提示框JLabel title=new JLabel();JLabel note1=new JLabel("*");JLabel note2=new JLabel("*");JLabel jlcourseID=new JLabel("课程号:"); //使用文本框创建标签对象JLabel jlteachername=new JLabel("教师号:");JTextField jtcourseID=new JTextField(); //创建文本框对象JTextField jtteachername=new JTextField();JButton submit=new JButton("添加"); //创建按钮对象JButton reset=new JButton("重置");public add_tc(){ //添加授课信息this.setTitle("添加授课信息"); //设置窗口标题this.setLayout(null); //设置窗口布局管理器this.add(jlcourseID); //将控件添加到窗体this.add(jlteachername);this.add(title);this.add(jtcourseID);this.add(jtteachername);this.add(note1);this.add(note2);this.add(submit);this.add(reset);this.add(warning);title.setFont(new Font("red",Font.BOLD,15)); //设置提示字体title.setForeground(Color.red);note1.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note1.setForeground(Color.red);note2.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note2.setForeground(Color.red);warning.setFont(new Font("red",Font.BOLD,12)); //设置提示字体warning.setForeground(Color.red);title.setText("添加授课信息"); //设置控件及窗体位置大小title.setBounds(222,20,150,20);jlcourseID.setBounds(180,80,100,20);jlteachername.setBounds(180,140,100,20);jtcourseID.setBounds(250,80,140,20);jtteachername.setBounds(250,140,140,20);note1.setBounds(400,80,140,20);note2.setBounds(400,140,140,20);submit.setBounds(200,250,60,20);reset.setBounds(300,250,60,20);warning.setBounds(420,140,150,20); //设置提示框位置大小submit.addActionListener(this); //添加监听器reset.addActionListener(this);this.setSize(600,400); //设置窗体大小centerShell(this); //设置窗口位置在屏幕中央this.setResizable(false); //设置窗体不可变大小this.setVisible(true); //设置窗口可见性this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(courseID);}return false;}public void actionPerformed(ActionEvent e){courseID=jtcourseID.getText(); //获取用户输入内容teachername=jtteachername.getText();int temp=0,flag1=0,flag2=0,flag3=0;Connection con=null;if(e.getSource()==submit){ //判断是否已输入必填信息if(courseID.equals("") || teachername.equals("")){warning.setText("请输入必填信息");}else{try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"",""); //获取连接字符串Statement stat=con.createStatement();ResultSet rs=stat.executeQuery("select Course_ID from Course");while(rs.next()){if(rs.getString(1).equals(courseID)){flag1=1; //判断课程ID存在break;}}ResultSet rss=stat.executeQuery("select Tea_ID fromTeacher_Info");while(rss.next()){if(rss.getString(1).equals(teachername)){flag2=1; //判断教师ID存在break;}}if(flag1!=1){warning.setText("课程ID不存在");}else if(flag2!=1){warning.setText("教师ID不存在");}ResultSet rsss=stat.executeQuery("select Course_ID,T ea_ID from tc");while(rsss.next()){if(rsss.getString(1).equals(courseID) &&rsss.getString(2).equals(teachername)){flag3=1;warning.setText("授课信息重复");。

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

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、设计目的学生信息管理系统是一个教育单位不可缺少的部分。

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

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

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

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

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

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

这些优点能够极大地提高学校信息管理的效率,也是一个单位科学化、正规化管理,与世界接轨的重要条件。

本系统是将现代化的计算机技术和传统的教学、教务工作相结合,按照学院的工作流程设计完成的。

通过一个简化的学生信息管理系统,使学生信息管理工作系统化、规范化、自动化,从而达到提高学生信息管理效率的目的。

二、分析与设计1、功能模块划分图1 功能模块划分图2、数据库结构描述2.1、数据库E-R模型图2 登录用户管理E-R图图3 实体学生E-R图2.2、数据库关系模型——二维表表1 学生表(student)stuZy nvarchar(30) 专业classId nvarchar(30) 班号stuSourse numeric(5,2) 总学分图4 录入数据后的学生表表2 登陆权限表(login)字段数据类型说明userId nvarchar(30) 用户名(账号),即登陆Idpassword nvarchar(30) 登陆密码position nvarchar(30) 职位,如班委,普通学生图5 录入数据后的登陆权限表3、系统详细设计文档3.1、系统执行流程图图6 系统执行流程图3.2、类的划分表3 学生信息查询类表4 修改学生信息类表5 修改管理人员信息类表6表模式-更新数据4、各个模块的实现方法描述说明:此处只包含了个人完成的模块的实现方法描述4.1、学生信息查询学生信息查询窗口,采用了基于管理窗口,即主界面的对话框实现,实现方法如下:1)定义查询所需要的面板和组件。

2)调用父类的构造方法,实现模式对话。

3)进行学生信息查询。

4.2、修改管理人员信息修改管理人员信息的界面,通过模式对话,即继承JDialog对话框来实现的,实现方法如下:1)定义修改学生信息的相关组件。

2)加载数据库,获得选中的那一行的所有信息。

3)把组件添加到窗体。

4)调用父类的构造方法,实现模式对话。

5)调用修改用户权限信息的界面的方法。

6)修改管理人员信息。

7)调用数据库连接,并设置操纵更新的sql语句。

4.3、修改学生信息修改学生信息的界面,通过模式对话,即继承JDialog对话框来实现,实现方法如下:1)定义修改学生信息的相关组件。

2)加载数据库,获得选中的那一行的所有信息。

3)把组件添加到窗体。

4)调用父类的构造方法,实现模式对话。

5)调用修改学生信息的界面的方法。

6)修改学生信息。

7)完成相应功能。

4.4、更新数据这是一个表模型,用于数据更新,实现方法如下:1)定义表格所需要的集合。

2)定义一个记录集,用于接收从数据库返回来的记录集。

3)定义一个用于连接数据库的对象。

4)设置表格的列名。

5)创建表的记录集。

6)调用数据库连接。

7)设置表的列名,并得到表的列数和行数。

8)得到某行某列的值。

5、测试数据及期望结果5.1、学生信息查询数据测试及期望结果数据测试及期望结果如下图:图7为学生登录后的最初界面;图8为学生查看所有信息界面;图9为全部学生的信息记录(此处同时运用到了TableModel类);图10则是实现了此处的查询功能,测试数据为:姓名:肖立本期望结果将显示以下数据:学号:904325 姓名:肖立本性别:男年龄:23 出生地:安徽专业:信息管理班级:9040303 总学分:542.5图7 学生信息管理系统图8 学生信息管理系统-显示记录图9 学生信息管理系统-显示所有信息图10 学生信息管理系统-学生信息查询5.2、修改管理人员数据测试及期望结果数据测试及期望结果如下图:图11将显示出所有管理人员信息。

此处测试的数据为:账号1:admin 密码1:admin 职位1:班委账号2:user 密码2:user 职位2:普通学生图12是弹出的修改密码窗口。

此处可将密码admin修改为其它值。

图11 显示所有管理人员信息图12 修改管理人员信息窗口5.3、修改学生信息数据测试及期望结果数据测试及期望结果如下图:图13为全部学生的信息记录(此处同时运用到了TableModel类);图14是弹出的修改学生信息窗口:测试数据:姓名:杨明辉期望结果:可修改姓名、性别、年龄、出生地、专业、班级和总学分。

图13 学生信息管理系统-显示所有信息图14 修改学生信息窗口三、系统测试1、系统启动界面图15 系统启动界面2、用户登录界面图16 用户登录界面3、班委(管理员)界面,即具有完全权限的用户后台界面图17 管理员界面4、班委(管理员)界面子菜单项显示图18 管理员界面子菜单-系统界面图19 管理员界面子菜单-学生管理界面图20 管理员界面子菜单-系统设置界面5、学生信息查询界面图21 学生信息查询6、学生信息查询结果显示图22 学生信息查询显示7、添加学生信息界面在没有输入学号或者姓名,以及某一项时,会弹出一个对话框进行提示,如没有输入学号时:图23 添加学生信息8、修改学生信息界面(学号是主键,灰色显示,即不可更改)图24 修改学生信息9、显示所有学生信息图25 显示所有信息10、当没有选中一行的时候,不能修改和删除,并弹出提示警告框图26 修改和删除警告框图11、删除文件时的确认对话框(点击确认时会删除,点击取消,则返回主界面)图27 删除学生确认对话框12、显示所有登陆用户信息图28 显示登录用户信息示意图13、修改用户登陆密码,选中某个用户进行修改图29 修改用户登录密码界面示意图14、关闭用户记录,即不显示所有用户信息图30 关闭用户记录示意图15、关闭学生记录图31 关闭学生记录示意图16、退出系统确认对话框只有确认时才会退出系统,否则返加主界面图32 退出系统17、普通学生登陆后的界面(即不能对学生信息进行添加,修改和删除以及用户密码修改,对应的这几项灰色显示,不可点击)图33 学生登录界面(1)图34 学生登录界面(2)四、心得体会这次为期一周的课程设计让我对java有了新的认识,首先我接触了很多上课见过但没有实际用过的类和方法,让我对编程有了许多新的思想。

大一学了C语言、C++等,虽然当时学的还不错,由于学的都是入门知识,所以自己做的程序只能实现一定的功能,和自己平时用的软件相差很大。

这学期刚开课学java,虽然知道这是一门很有用的语言,但是却感觉没什么新鲜感,它的跨平台特性也只是听听,根本没有认识,由于平时学习不刻苦,也没有时间静下心来写过java代码,当得知最后期末最后一周将进行java课程设计,才静下心来开始研究java,结合以前的编程知识,做起了自己的程序。

与此同时,我们也在进行数据库课程设计,和这个系统相类似,,做起来比较熟练,同时想通过做课程设计将数据库和java更好的结合运用起来,感觉这样才能够更贴近实际应用。

这次课程设计使我对java的跨平台性有了进一步认识,同时加深了课堂上所学到的知识。

虽然这是第三次课程设计,并且自己也有了两年的上机实验,但我不得不说这一次课程设计是前两次以及任何一节上机实验课都不可比的。

在课程设计这一段时间,使我收获了很多在上机课上无法学习到的知识,尤其是需求分析和eclipse熟练的使用。

因为这一部分知识的不熟练,在程序设计过程中遇到了不少困难,但通过老师的指导和一次又一次的指导、改写、调试,将这些困难都解决了,心中的喜悦感油然而生。

为了能使程序更加的完善,更加人性化,我也利用了不少的课余时间,查找了各方面的资料,看到一个小型系统能够展示在电脑屏幕上时,感觉自己这段时间的付出是非常值得的,也使我对java产生了更浓厚的兴趣,对自己的学习以及将来的工作都是有很大的帮助的。

整个课程设计过程让我的java知识得到了应用,体验了程序员编程时的喜怒哀乐,知识、心智,得到全方位提升,收获颇丰。

五、参考文献著作文献:[1] 赵海廷.Java语言程序设计教程.北京:清华大学出版社.2012[2] 孙印杰,刘斌,孙玉强.Java编程案例精解.北京:电子工业出版社.2005[3] 何梅.java编程实例系列丛书.北京:清华大学出版社,2002[4] 杨昭.二级Java语言程序设计教程.北京:中国水利水电出版社,2006[5] 赵文靖.Java程序设计基础与上机指导.北京:清华大学出版社,2006六、附录1、功能:这是学生信息查询窗口,采用基于管理窗口,即主界面的对话框实现package com.View;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;import com.Tools.MyFont;public class StuQuery extends JDialog implements ActionListener{ //定义查询所需要的面板和组件JPanel jp1;JLabel jp1_jl1;JTextField jp1_jtf1;JButton jp1_jb1,jp1_jb2,jp1_jb3;JTable jtb;JScrollPane jsp;TableModel tm;public StuQuery(Frame Main,String title ,boolean model) {//调用父类的构造方法,实现模式对话super(Main,title,model);jp1=new JPanel();jp1_jl1=new JLabel("请输入姓名:");jp1_jl1.setFont(MyFont.f1);jp1_jtf1=new JTextField(15);jp1_jb1=new JButton("查询->");jp1_jb1.setFont(MyFont.f1);jp1_jb1.addActionListener(this);jp1_jb2=new JButton("清除");jp1_jb2.setFont(MyFont.f1);jp1_jb2.addActionListener(this);jp1_jb3=new JButton("显示所有记录");jp1_jb3.setFont(MyFont.f1);jp1_jb3.addActionListener(this);jp1.add(jp1_jl1);jp1.add(jp1_jtf1);jp1.add(jp1_jb1);jp1.add(jp1_jb2);jp1.add(jp1_jb3);jtb=new JTable();jsp=new JScrollPane(jtb);this.add(jp1,"North");this.add(jsp,"Center");this.setSize(600,400);this.setVisible(true);}@Overridepublic void actionPerformed(ActionEvent arg0) {// TODO Auto-generated method stub//如果点击了查询按钮if(arg0.getSource()==jp1_jb1){//获取文本框的值String stuName=jp1_jtf1.getText().trim();//其中trim()是去掉文本框前面可能有的空格,但不能去掉字符串中的空格String sql="select * from student where stuName='"+stuName+"'";//调用模型tm=new TableModel(sql);jtb.setModel(tm);}else if(arg0.getSource()==jp1_jb2){jp1_jtf1.setText("");}else if(arg0.getSource()==jp1_jb3){tm=new TableModel(null);jtb.setModel(tm);}}}2、功能:这是一个表模型,用于更新数据package com.View;import com.SqlConnection.*;//引入数据库连接的包import java.sql.*;import java.util.*;import javax.swing.table.AbstractTableModel;import com.SqlConnection.SqlConn;public class TableModel extends AbstractTableModel {//定义表格所需要的集合Vector rowData,row,column;//定义一个记录集,用于接收从数据库返回来的记录集ResultSet rs;//定义一个用于连接数据库的对象SqlConn conn;public TableModel(String sql){if(sql==null){sql="select * from student";}//设置表格的列名column=new Vector();column.add("学号");column.add("姓名");column.add("性别");column.add("年龄");column.add("出生地");column.add("专业");column.add("班级");column.add("总学分");//创建表的记录集rowData=new Vector();//调用数据库连接conn=new SqlConn();rs=conn.sqlQuery(sql);try {while(rs.next()){row=new Vector();row.add(rs.getString(1));row.add(rs.getString(2));row.add(rs.getString(3));row.add(rs.getString(4));row.add(rs.getString(5));row.add(rs.getString(6));row.add(rs.getString(7));row.add(rs.getString(8));rowData.add(row);}} catch (Exception e) {e.printStackTrace();// TODO: handle exception }}@Override//设置表的列名public String getColumnName(int column) {// TODO Auto-generated method stubreturn (String)this.column.get(column);}@Override//得到的列数public int getColumnCount() {// TODO Auto-generated method stubreturn this.column.size();}//得到的行数@Overridepublic int getRowCount() {// TODO Auto-generated method stubreturn this.rowData.size();}@Override//得到某行某列的值public Object getValueAt(int arg0, int arg1) {// TODO Auto-generated method stubreturn ((Vector)this.rowData.get(arg0)).get(arg1);}}3、功能:这是修改管理人员信息的界面,通过模式对话(即继承JDialog对话框)来实现package com.View;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;import com.SqlConnection.SqlConn;import com.Tools.MyFont;public class UpdateLogin extends JDialog implements ActionListener { //定义修改学生信息的相关组件JLabel jl1,jl2,jl3;JTextField jtf1,jtf2,jtf3;JButton jb1,jb2,jb3;//这是修改账户信息权限的界面函数的封装public void upView(){//加载数据库,获得选中的那一行的所有信息jl1=new JLabel("账号:");//因为账号是主键,设置文本框不可编辑的同时,一般也设置标签灰色显示,以区别其他标签jl1.setEnabled(false);jl1.setBounds(20, 20, 60, 25);jl1.setFont(MyFont.f1);jl2=new JLabel("密码:");jl2.setFont(MyFont.f1);jl2.setBounds(250, 20, 60, 25);jl3=new JLabel("职位:");jl3.setEnabled(false);jl3.setFont(MyFont.f1);jl3.setBounds(20, 60, 60, 25);jtf1=new JTextField(20);//由于账号是主键,因此不能修改,即设置障碍曙jtf1不可编辑jtf1.setEnabled(false);jtf1.setBounds(70, 20, 130, 25);jtf2=new JTextField(20);jtf2.setBounds(300, 20, 130, 25);jtf3=new JTextField(20);jtf3.setEnabled(false);jtf3.setBounds(70, 60, 130, 25);jb1=new JButton("修改");jb1.setFont(MyFont.f1);jb1.setBounds(100, 100, 80, 25);jb1.addActionListener(this);jb2=new JButton("取消");jb2.setFont(MyFont.f1);jb2.setBounds(280, 100, 80, 25);jb2.addActionListener(this);jb3=new JButton("清除");jb3.setFont(MyFont.f1);jb3.setBounds(190,100,80,25);jb3.addActionListener(this);this.setLayout(null);//把组件添加到窗体this.add(jl1);this.add(jtf1);this.add(jl2);this.add(jtf2);this.add(jl3);this.add(jtf3);this.add(jb1);this.add(jb2);this.add(jb3);}//因为要修改信息,那么必须要获得所选中的那一行的所有信息,把它们添加到文本框作为默认值,因此构造方法还应添加一个参数即传递一个模型tm,并传递所选中的行号rowpublic UpdateLogin(Frame Main,String title,PurViewModel pvm,int rowNo,boolean model){//调用父类的构造方法,实现模式对话super(Main,title,model);//调用修改用户权限信息的界面的方法this.upView();//先从表模型中获取所选中的那一行数据String userId=(String)pvm.getValueAt(rowNo, 0);System.out.println("userId="+userId);String password=(String)pvm.getValueAt(rowNo, 1);String position=(String)pvm.getValueAt(rowNo, 2);//设置广本框的值jtf1.setText(userId);jtf2.setText(password);jtf3.setText(position);//设置窗体的属性this.setSize(465,170);this.setVisible(true);this.setResizable(false);}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub//当点击了修改按钮if(e.getSource()==jb1){//获取文本框的信息String userId=jtf1.getText().trim();String password=jtf2.getText().trim();String position=jtf3.getText().trim();//调用数据库连接//设置操纵更新的sql语句String sql="update login set password='"+password+"',position='"+position+"'whereuserId='"+userId+"'";SqlConn sqlconn=new SqlConn();sqlconn.sqlUpdate(sql);//关闭交资源sqlconn.closeSqlConn();//关闭与数据库连接的资源后,再关闭对话框,否则数据不能自动在表中更新显示出来this.dispose();}//如果点击了取消按钮,则关闭模式对话框else if(e.getSource()==jb2){this.dispose();}//如果点击了清除按钮,则清除所有的广本框的内容,除了学号else if(e.getSource()==jb3){//由于账号是主键,则不能清空!jtf2.setText("");}}}4、功能:这是修改学生信息的界面,通过模式对话(即继承JDialog对话框)来实现package com.View;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;import com.SqlConnection.SqlConn;import com.Tools.MyFont;public class UpdateStu extends JDialog implements ActionListener {//定义修改学生信息的相关组件JLabel jl1,jl2,jl3,jl4,jl5,jl6,jl7,jl8;JTextField jtf1,jtf2,jtf3,jtf4,jtf5,jtf6,jtf7,jtf8;JButton jb1,jb2,jb3;int stuAge=0;Double stuSourse=0.0;//这是修改学生信息的界面函数的封装public void upView(){//加载数据库,获得选中的那一行的所有信息jl1=new JLabel("学号:");//因为学号是主键,设置文本框不可编辑的同时,一般也设置标签灰色显示,以区别其他标签jl1.setEnabled(false);jl1.setBounds(20, 20, 60, 25);jl1.setFont(MyFont.f1);jl2=new JLabel("姓名:");jl2.setFont(MyFont.f1);jl2.setBounds(250, 20, 60, 25);jl3=new JLabel("性别:");jl3.setFont(MyFont.f1);jl3.setBounds(20, 60, 60, 25);jl4=new JLabel("年龄:");jl4.setFont(MyFont.f1);jl4.setBounds(250, 60, 60, 25);jl5=new JLabel("出生地:");jl5.setFont(MyFont.f1);jl5.setBounds(14, 100, 60, 25);jl6=new JLabel("专业:");jl6.setFont(MyFont.f1);jl6.setBounds(20, 140, 60, 25);jl7=new JLabel("班级:");jl7.setFont(MyFont.f1);jl7.setBounds(20, 180, 60, 25);jl8=new JLabel("总学分:");jl8.setFont(MyFont.f1);jl8.setBounds(240, 180, 60, 25);jtf1=new JTextField(20);//由于学号是主键,因此不能修改,即设置障碍曙jtf1不可编辑jtf1.setEnabled(false);jtf1.setBounds(70, 20, 130, 25);jtf1.setBorder(BorderFactory.createLoweredBevelBorder());jtf2=new JTextField(20);jtf2.setBounds(300, 20, 130, 25);jtf2.setBorder(BorderFactory.createLoweredBevelBorder());jtf3=new JTextField(10);jtf3.setBounds(70, 60, 60, 25);jtf3.setBorder(BorderFactory.createLoweredBevelBorder());jtf4=new JTextField(10);jtf4.setBounds(300, 60, 60, 25);jtf4.setBorder(BorderFactory.createLoweredBevelBorder());jtf5=new JTextField(30);jtf5.setBounds(70, 100, 360, 25);jtf5.setBorder(BorderFactory.createLoweredBevelBorder());jtf6=new JTextField(20);jtf6.setBounds(70, 140, 290, 25);jtf6.setBorder(BorderFactory.createLoweredBevelBorder());jtf7=new JTextField(20);jtf7.setBounds(70, 180, 130, 25);jtf7.setBorder(BorderFactory.createLoweredBevelBorder());jtf8=new JTextField(20);jtf8.setBounds(300, 180, 130, 25);jtf8.setBorder(BorderFactory.createLoweredBevelBorder());jb1=new JButton("修改");jb1.setFont(MyFont.f1);jb1.setBounds(100, 220, 80, 25);jb1.addActionListener(this);jb2=new JButton("取消");jb2.setFont(MyFont.f1);jb2.setBounds(280, 220, 80, 25); jb2.addActionListener(this);jb3=new JButton("清除");jb3.setFont(MyFont.f1);jb3.setBounds(190,220,80,25);jb3.addActionListener(this);this.setLayout(null);//把组件添加到窗体this.add(jl1);this.add(jtf1);this.add(jl2);this.add(jtf2);this.add(jl3);this.add(jtf3);this.add(jl4);this.add(jtf4);this.add(jl5);this.add(jtf5);this.add(jl6);this.add(jtf6);this.add(jl7);this.add(jtf7);this.add(jl8);this.add(jtf8);this.add(jb1);this.add(jb2);this.add(jb3);}//因为要修改信息,那么必须要获得所选中的那一行的所有信息,把它们添加到文本框作为默认值,因此构造方法还应添加一个参数即传递一个模型tm,并传递所选中的行号rowpublic UpdateStu(Frame Main,String title,TableModel tm,int rowNo,boolean model){//调用父类的构造方法,实现模式对话super(Main,title,model);//调用修改学生信息的界面的方法this.upView();//先从表模型中获取所选中的那一行数据String stuId=(String)tm.getValueAt(rowNo, 0);System.out.println("sutId="+stuId);String stuName=(String)tm.getValueAt(rowNo, 1);String stuSex=(String)tm.getValueAt(rowNo, 2);String stuAge=(String)tm.getValueAt(rowNo, 3);String stuJg=(String)tm.getValueAt(rowNo, 4);String stuZy=(String)tm.getValueAt(rowNo, 5);String classId=(String)tm.getValueAt(rowNo, 6);String stuSourse=(String)tm.getValueAt(rowNo, 7);//设置文本框的默认值jtf1.setText(stuId);jtf2.setText(stuName);jtf3.setText(stuSex);jtf4.setText(stuAge);jtf5.setText(stuJg);jtf6.setText(stuZy);jtf7.setText(classId);jtf8.setText(stuSourse);//设置窗体的属性this.setSize(465,300);this.getContentPane().setBackground(Color.LIGHT_GRAY);this.setVisible(true);this.setResizable(false);}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub//当点击了修改按钮if(e.getSource()==jb1){//获取文本框的信息String stuId=jtf1.getText().trim();String stuName=jtf2.getText().trim();if(stuName.equals("")){JOptionPane.showMessageDialog(this, "请输入姓名!");return;//返回到输入界面,如果没有return语句,则会回到主界面}String stuSex=jtf3.getText().trim();if(stuSex.equals("")){JOptionPane.showMessageDialog(this, "请输入性别!");return;//返回到输入界面,如果没有return语句,则会回到主界面}////对于年龄,则需要进行两个判断,一个是不能为空,另一个必须是int 型,下面用异常来判断输入的学生年龄是否是整型数//******************************************//try {stuAge=Integer.parseInt(jtf4.getText().trim());//把从文本框取得的字符串转换成整型,如果抛异常,则输入的不是整形数if(stuAge<1){JOptionPane.showMessageDialog(this, "年龄必须大于或等于1!");return;}} catch (Exception e2) {//提示输入的不是整数JOptionPane.showMessageDialog(this, "请输入一个整数的年龄!");//如果抛异常,则返回到添加窗口,后面终止执行******************************//return;// TODO: handle exception}//****************************************************************** *//String stuJg=jtf5.getText().trim();if(stuJg.equals("")){JOptionPane.showMessageDialog(this, "请输入出生地!");return;//返回到输入界面,如果没有return语句,则会回到主界面}String stuZy=jtf6.getText().trim();if(stuZy.equals(""))。

相关文档
最新文档