资源描述
页眉学生成绩管理系统课程设计实验报告题 目学生成绩管理系统学 院专 业班 级同组成员编写日期页脚一、课程设计目的做这个小的学生成绩管理系统来加深对JAVA所学知识的巩固,以及学习JAVA 与数据库的连接和JAVA 的 GUI 图形界面。二、需求分析此系统实现如下系统功能:(1)使得学生的成绩管理工作更加清晰、条理化、自动化。(2)通过用户名和密码登录系统,查询学生基本资料,学生所学课程成绩,等功能。容易地完成学生信息的查询操作。(3) 设计人机友好界面,功能安排合理,操作使用方便,并且进一步考虑系统在安全性,完整性,并发控制,备份和恢复等方面的功能要求。三、系统模块设计此系统可分为 2 个模块,教师管理模块和学生操作模块,期中教师又包括学生信息输入与学生成绩录入等; 学生模块则包括学生成绩查询与学生信息录入查询操作等。用户登录系统流程图:教师学生1学学学学生生生生成信成信四、数据库1、学生表:FieldTypeNullKeyCommentIDVarchar(1PRI用户名 (学号 )0)PwdVarchar(1密码0)NameChar(10)姓名SexChar(10)性别2ClassChar(10)班级CollageChar(10)学院2、教师表FieldTypeNullKeyCommentIDVarchar(1PRI用户名0)PwdVarchar(1密码0)3、成绩表FieldTypeNullKeyCommentSidchar(10)PRI学号计算机网络char(10)课程Linux 操作系统char(10)课程计算机专业英语char(10)课程计算机信息技术char(10)课程Java 程序设计char(10)课程数据库应用实训char(10)课程高等数学char(10)课程XMLchar(10)课程五、 E-R 图3ClassIDClocageIDPwd学生表TS教师表PwdSexSC计算机网络name计算机专业英Linux 操作系语统计算机系成绩计算机信息技数据库应用实术基础训教程Java 程序设计高等数学SID(ID)XML附录:源代码1、用户登录界面public class Systems extends JFrame implements ActionListenerstatic Systems ss;JPanel panel = new JPanel();4JLabel label1 = new JLabel(输入姓名: );JTextField name = new JTextField();JLabel label2 = new JLabel(密码: );JPasswordField pwd = new JPasswordField();JButton Enter = new JButton(登录 );JButton Exit = new JButton(退出 );String url = E:mysqlTM1.jpg;ButtonGroup bgp = new ButtonGroup();JRadioButton stu = new JRadioButton(学生 );JRadioButton tch = new JRadioButton(教师 );public Systems()super( 登录系统 );this.setResizable(false);JLabel img = new JLabel(new ImageIcon(url);img.setBounds(0,0,500,125);panel.add(img);stu.setBounds(165,210,70,20);tch.setBounds(265,210,70,20);bgp.add(stu);bgp.add(tch);5panel.add(stu);panel.add(tch);Enter.setBounds(150,250,80,20);Exit.setBounds(270,250,80,20);Enter.addActionListener(this);Exit.addActionListener(this);panel.add(Enter);panel.add(Exit);panel.setLayout(null);this.add(panel);label1.setBounds(135,130,100,25);panel.add(label1);name.setBounds(265,130,100,25);panel.add(name);label2.setBounds(135,165,100,25);panel.add(label2);pwd.setBounds(265,165,100,25);panel.add(pwd);this.setBounds(100,100,500,350);this.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);6public void actionPerformed(ActionEvent e)if(e.getSource()=Enter)String username , password;username = name.getText();password = new String(pwd.getPassword();trycatch (ClassNotFoundException ce)JOptionPane.showMessageDialog(ss,ce.getMessage();if(stu.isSelected()tryConnectioncon=7DriverManager.getConnection(jdbc:odbc:shujuku,sa,);Statement stmt = con.createStatement();ResultSetrs = stmt.executeQuery(select* fromSTU);while(rs.next()if(rs.getString(ID).equals(username)if(rs.getString(Pwd).equals(password)JOptionPane.showMessageDialog(ss,登陆成功 );Students stu = new Students();elseJOptionPane.showMessageDialog(ss,登录失败 );rs.close();stmt.close();8catch (SQLException se)JOptionPane.showMessageDialog(ss,se.getMessage();else if(tch.isSelected()tryConnectioncon=DriverManager.getConnection(jdbc:odbc:shujuku,sa,);Statement stmt = con.createStatement();ResultSetrs = stmt.executeQuery(select*fromTCH);while(rs.next()if(rs.getString(ID).equals(username)if(rs.getString(Pwd).equals(password)JOptionPane.showMessageDialog(ss,登陆成功 );9Teachers tch=new Teachers();elseJOptionPane.showMessageDialog(ss,登录失败 );catch (SQLException se)JOptionPane.showMessageDialog(ss,se.getMessage();elseSystem.exit(0);10public static void main(String args)Systems sys = new Systems();2、学生登录界面:public class Students extends JFrame implements ActionListenerJMenuBar jmb = new JMenuBar();JMenu Message = new JMenu(信息 );JMenu Score = new JMenu(成绩 );JMenuItem Item1 = new JMenuItem(插入 );JMenuItem Item2 = new JMenuItem(查询 );JMenuItem Item3 = new JMenuItem(查询 );public Students()11super( 学生界面 );this.setSize(500,400);this.setVisible(true);this.setResizable(false);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setJMenuBar(jmb);jmb.add(Message);jmb.add(Score);Message.add(Item1);Message.add(Item2);Score.add(Item3);Item1.addActionListener(this);Item2.addActionListener(this);Item3.addActionListener(this);public void actionPerformed(ActionEvent e)if(e.getSource()=Item1)AddMsg ad = new AddMsg();12else if(e.getSource()=Item2)Serch ser = new Serch();elseScore so = new Score();public static void main(String args)Students stu = new Students();3、教师登录界面:public class Teachers extends JFrame implements ActionListener13JMenuBar bar = new JMenuBar();JMenu menu1 = new JMenu(信息 );JMenu menu2 = new JMenu(成绩 );JMenuItem item1 = new JMenuItem(录入信息 );JMenuItem item2 = new JMenuItem(录入成绩 );JPanel jpl = new JPanel();public Teachers()super( 教师界面 );this.setSize(500,300);this.setResizable(false);this.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setJMenuBar(bar);this.add(jpl);jpl.setLayout(null);bar.add(menu1);bar.add(menu2);menu1.add(item1);menu2.add(item2);14item1.addActionListener(this);item2.addActionListener(this);public void actionPerformed(ActionEvent e)if(e.getSource()=item1)AddMsg msg = new AddMsg();elseAddscore as = new Addscore();public static void main(String args)Teachers tch = new Teachers();154、学生用户添加界面:public class AddMsg extends JFrame implements ActionListenerstatic AddMsg s;/* 添加学生信息控件 */JPanel jpl = new JPanel();JLabel label1 = new JLabel(添加基本信息 ,JLabel.CENTER);JLabel label2 = new JLabel(学号: ,JLabel.CENTER);JLabel label3 = new JLabel(姓名: ,JLabel.CENTER);JLabel label4 = new JLabel(性别: ,JLabel.CENTER);JLabel label5 = new JLabel(班级: ,JLabel.CENTER);JLabel label6 = new JLabel(学院: ,JLabel.CENTER);JTextField num = new JTextField(2);JTextField nam = new JTextField(4);ButtonGroup bgp = new ButtonGroup();JRadioButton man = new JRadioButton(男);JRadioButton women = new JRadioButton(女);16JTextField clas = new JTextField();JTextField scl = new JTextField();JButton reset = new JButton(重置 );JButton addmsg = new JButton(添加 );public AddMsg()super( 添加学生信息 );this.setResizable(false);this.setSize(500,400);this.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.add(jpl);jpl.setLayout(null);addmsg.addActionListener(this);reset.addActionListener(this);/* 插入面板 */label1.setBounds(100,20,300,20);jpl.add(label1);label2.setBounds(100,50,70,20);jpl.add(label2);num.setBounds(190,50,140,20);17jpl.add(num);label3.setBounds(100,90,70,20);jpl.add(label3);nam.setBounds(190,90,140,20);jpl.add(nam);label4.setBounds(100,130,70,20);jpl.add(label4);man.setBounds(190,130,60,20);women.setBounds(270,130,60,20);jpl.add(man);jpl.add(women);bgp.add(man);bgp.add(women);label5.setBounds(100,170,70,20);jpl.add(label5);clas.setBounds(190,170,140,20);jpl.add(clas);label6.setBounds(100,210,70,20);jpl.add(label6);scl.setBounds(190,210,140,20);jpl.add(scl);reset.setBounds(120,250,90,20);18addmsg.setBounds(240,250,90,20);jpl.add(reset);jpl.add(addmsg);public void actionPerformed(ActionEvent e)if(e.getSource()=addmsg)String sex;if(man.isSelected()sex= 男;elsesex= 女;try19catch (ClassNotFoundException ce)JOptionPane.showMessageDialog(s,ce.getMessage();tryConnectioncon=DriverManager.getConnection(jdbc:odbc:shujuku,sa,);Statement stmt = con.createStatement();String str = insert into STU(ID ,Pwd ,Name, Sex , Class ,Collage)values(+num.getText()+,+123,+nam.getText()+,+sex+,+clas.getText()+,+scl.getText()+);/inta = stmt.executeUpdate(insertintoSTU(ID , Pwd,Name,Sex,Class,Collage)values(+num.getText()+,+12345678,+nam.getText()+,+sex+,+clas.getText()+,+scl.getText()+);int a = stmt.executeUpdate(str);if(a=1)JOptionPane.showMessageDialog(s,已成功添加 );20elseJOptionPane.showMessageDialog(s,添加失败 );stmt.close();catch (SQLException se)JOptionPane.showMessageDialog(s,se.getMessage();elsenum.setText();nam.setText();clas.setText();scl.setText();num.requestFocus();public static void main(String args)21AddMsg amg = new AddMsg();5、学生成绩添加:public class Addscore extends JFrame implements ActionListenerstatic Addscore ss;JLabel label = new JLabel(学号: ) , new JLabel(计算机网络: ) ,newJLabel(Linux操作系统: ) , newJLabel( 计算机专业英语: ) , newJLabel( 计算机信息技术基础:) , newJLabel(Java程序设计: ) , newJLabel( 数 据 库应 用实 训教 程: ) ,newJLabel( 高 等数 学: ) , newJLabel(XML :);JTextFieldtxt=newJTextField(),newJTextField(),newJTextField(), newJTextField(), newJTextField(),newJTextField(), newJTextField() ,new JTextField() ,new JTextField() ;JButton add = new JButton(添加 );22JButton reset = new JButton(重置 );JPanel jpl = new JPanel();JLabel title = new JLabel(添加学生成绩 , JLabel.CENTER);Font f = new Font(黑体 , Font.BOLD , 16 );int s = 100;public Addscore()super( 添加学生信息 );this.setResizable(false);this.setSize(500,600);this.setDefaultCloseOperation(EXIT_ON_CLOSE);this.setVisible(true);this.add(jpl);add.addActionListener(this);reset.addActionListener(this);jpl.setLayout(null);title.setBounds(150,40,200,20);title.setFont(f);title.setForeground(Color.red);jpl.setBackground(Color.LIGHT_GRAY);jpl.add(title);23for(int i = 0 ; i label.length ; i+)labeli.setBounds(100,s,140,20);jpl.add(labeli);txti.setBounds(260,s,140,20);jpl.add(txti);s=s+40;add.setBounds(150,s,80,20);reset.setBounds(250,s,80,20);jpl.add(add);jpl.add(reset);public void actionPerformed(ActionEvent e)if(e.getSource()=add)try24catch (ClassNotFoundException ce)JOptionPane.showMessageDialog(ss,ce.getMessage();tryConnectioncon=DriverManager.getConnection(jdbc:odbc:shujuku,sa,);Statement stmt = con.createStatement();int a = stmt.executeUpdate(insert into计算机系成绩 (SID ,计算机网络, Linux 操作系统, 计算机专业英语, 计算机信息技术基础, Java程序设计,数据库应用实训教程,高等数学,Xml)values(+txt0.getText()+,+txt1.getText()+,+txt2.getText()+,+txt3.getText()+,+txt4.getText()+,+txt5.getText()+,+txt6.getText()+,+txt7.getText()+,+txt8.getText()+);if(a=1)JOptionPane.showMessageDialog(ss,添加成功 );elseJOptionPane.showMessageDialog(ss,添加失败 );25catch (SQLException se)JOptionPane.showMessageDialog(ss,se.getMessage();elsefor(int i = 0 ; itxt.length ; i+)txti.setText();txt0.requestFocus();public static void main(String args)Addscore as = new Addscore();266、学生信息查询:public class Serch extends JFrame implements ActionListener/* 查询学生信息控件 */static Serch s;JPanel jpl = new JPanel();JLabel SCH = new JLabel(查询学生信息 ,JLabel.CENTER);JLabel label1 = new JLabel(请输入学号: ,JLabel.CENTER);JButton serch = new JButton(查询 );JLabel label2 = new JLabel(姓名: ,JLabel.CENTER);JLabel label3 = new JLabel(班级: ,JLabel.CENTER);JLabel label4 = new JLabel(学校: ,JLabel.CENTER);JLabel label5 = new JLabel(性别: ,JLabel.CENTER);ButtonGroup bgp = new ButtonGroup();JRadioButton man = new JRadioButton(男);JRadioButton women = new JRadioButton(女);27JTextField num = new JTextField();JTextField nam = new JTextField();JTextField clas = new JTextField();JTextField scl = new JTextField();JButton reset = new JButton(重置 );public Serch()this.setSize(500,400);this.setVisible(true);this.setResizable(false);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.add(jpl);jpl.setLayout(null);serch.addActionListener(this);reset.addActionListener(this);/* 查询面板 */SCH.setBounds(100,20,300,20);jpl.add(SCH);label1.setBounds(100,60,100,20);jpl.add(label1);num.setBounds(220,60,140,20);28jpl.add(num);serch.setBounds(120,100,90,20);reset.setBounds(260,100,90,20);jpl.add(serch);jpl.add(reset);label2.setBounds(100,140,70,20);jpl.add(label2);nam.setBounds(190,140,140,20);jpl.add(nam);label5.setBounds(100,180,70,20);jpl.add(label5);man.setBounds(205,180,60,20);women.setBounds(285,180,60,20);bgp.add(man);bgp.add(women);jpl.add(man);jpl.add(women);label3.setBounds(100,220,70,20);jpl.add(label3);clas.setBounds(190,220,140,20);jpl.add(clas);label4.setBounds(100,260,70,20);29jpl.add(label4);scl.setBounds(190,260,140,20);jpl.add(scl);public void actionPerformed(ActionEvent e)String id = num.getText();if(e.getSource()=serch)trycatch (ClassNotFoundException ce)JOptionPane.showMessageDialog(s,ce.getMessage();tryConnectioncon=DriverManager.getConnection(jdbc:odbc:shujuku,sa,);30Statement stmt = con.createStatement();ResultSet rs = stmt.executeQuery(select * from STU whereID = + id + );while(rs.next()nam.setText(rs.getString(Name);if(rs.getString(Sex).equals(男)man.setSelected(true);elsewomen.setSelected(true);clas.setText(rs.getString(Class);scl.setText(rs.getString(Collage);catch (SQLException se)JOptionPane.showMessageDialog(s,se.getMessage();31public static void main(String args)Serch sch = new Serch();7、学生成绩查询public class Score extends JFrame implements ActionListenerstatic Score s;JLabel title = new JLabel(查询成绩 ,JLabel.CENTER);Font f = new Font(楷体 ,Font.BOLD+Font.ITALIC,16);JPanel jpl = new JPanel();32JLabel label1 = new JLabel(请输入学号: ,JLabel.CENTER);JTextField num = new JTextField();JButton serch = new JButton(查询成绩 );JButton reset = new JButton(重置 );JLabel label2 = new JLabel(计算机网络: ,JLabel.LEFT);JLabel label3 = new JLabel(Linux操作系统: ,JLabel.LEFT);JLabel label4 = new JLabel(计算机专业英语: ,JLabel.LEFT);JLabel label5 = new JLabel(计算机信息技术基础: ,JLabel.LEFT);JLabel label6 = new JLabel(Java程序设计: ,JLabel.LEFT);JLabel label7 = new JLabel(数据库: ,JLabel.LEFT);JLabel label8 = new JLabel(高等数学: ,JLabel.LEFT);JLabel label9 = new JLabel(XML:,JLabel.LEFT);JTextFieldtxt=newJTextField(),newJTextField(),newJTextField(), newJTextField(), newJTextField(), newJTextField(),newJTextField() , new JTextField();static int p = 140;public Score()super( 查询分数 );this.setResizable(false);33this.setSize(500,550);this.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);title.setFont(f);this.add(jpl);jpl.setLayout(null);title.setBounds(100,20,300,20);jpl.ad
展开阅读全文