1、一个简单的学生成绩管理信息系统(Java)年月一个简单的学生成绩管理信息系统题目:题目:数据库要求:1.建立的数据库中包含如下信息:学生学号、姓名、班级,语文、数学、英语 成绩。2.至少要有 5 个班级,每个班级要有 10 名以上学生。3.使用.txt 格式文本表示各种表。功能需求:4.能够实现根据以下关键字查询:学生姓名、学号、班级、课程名称。5.能够实现按照单科成绩、总成绩、平均成绩、学号排序。6.能够实现学生信息的插入、删除和修改。7.能够查询每个课程的最高分、最低分及相应学生姓名、班级和学号。8.能够查询每个班级某门课程的优秀率(90 分及以上)、不及格率,并进行排 序。界面要求:使用
2、图形界面实现,要符合日常软件使用规范来设计菜单和界面。一、需求分析1、界面、界面符合日常软件使用规范,使用方便,外形简洁美观。2、功能需求、功能需求存储学生学号、姓名、班级,语文、数学、英语成绩等信息,实现数据库 的读取与存入,数据项的记录与修改,删除等。二、设计思想1、类设计、类设计将添加数据、查询数据、删除数据、修改数据四个功能分别为四个类来实现,为了便于测试,每一个类都继承了主窗口类 JFRAME,使得窗口可以独自运行。INSERT 类设计功能组件 功能实现 实现过程6 个文本域、6 个标签、1 个按钮 添加数据对按钮添加监控,实现按钮事件为获取文本域中的信息,并执行实现过程与添加数据类
3、似,对按钮添加监控,实现按钮事件为获取文本域 中的信息,并执行 SQL 的 UPDATE 语句;不同的是以学号为主键进行查找并更新。DELETE 类设计功能组件 功能实现 实现过程1 个单行文本、1 个标签、1 个按钮、1 个多行文本 删除数据与修改数据类似,对按钮添加监控,实现按钮事件为获取文本域中的学号信息,并执行 SQL 的 DELETE 语句;不同的是以学号为主键进行查找并 将删除信息输出到文本框中。2、数据库设计、数据库设计系统概念结构设计成绩查询系统学号姓名语文数学数学Maths长整数数据库截图3、主界面设计、主界面设计MAINFRAME 类设计功能组件 功能实现 实现过程4 个按
4、钮、1 个背景、2 个标签文本、2 个面板 查询数据、添加数据、删除数据、修改数据对按钮添加监控,共有 4 个监控事件,实现按钮事件为创建对应功能的类对象,出现相应的功能窗口。三、运行截图添加数据添加数据查询数据查询数据按学号查询按学号查询按课程名称查询按课程名称查询修改数据修改数据删除数据删除数据五、源代码清单MainFrame 类类 import javax.swing.*;import java.awt.*;import java.awt.event.*;public class MainFrame extends JFrameJButton insert,query,delete,mo
5、dify;JPanel panel,panel1,panel2;public MainFrame()/TODO Auto-generated method stub ImageIcon img=new ImageIcon(1.gif);JLabel text1,text2,picture=new JLabel(img);JFrame frame=new JFrame(学生成绩管理系统);insert=new JButton(添 加 数 据);insert.setBackground(Color.green);insert.addActionListener(new insertActionPe
6、rformed();query=new JButton(查 询 数 据);query.addActionListener(new queryActionPerformed();query.setBackground(Color.green);modify=new JButton(修 改 数 据);modify.setBackground(Color.green);modify.addActionListener(new modifyActionPerformed();delete=new JButton(删 除 数 据);delete.setBackground(Color.green);de
7、lete.addActionListener(new deleteActionPerformed();frame.setSize(360,200);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);Container contentPane=frame.getContentPane();contentPane.setLayout(new BorderLayout();text1=new JLabel(欢迎用学生成绩管理系统,JLabel.CENTER);text1.setFont(new Font(宋体,Font.BOLD,24);tex
8、t1.setForeground(Color.blue);text2=new JLabel(-192091班 罗斌制作);text2.setFont(new Font(TimesRoman,Font.ROMAN_BASELINE,14);panel1=new JPanel();panel1.add(insert);panel1.add(query);panel2=new JPanel();panel2.add(modify);panel2.add(delete);panel1.setOpaque(false);panel2.setOpaque(false);panel=new JPanel()
9、;panel.add(text2,BorderLayout.NORTH);panel.add(panel1,BorderLayout.NORTH);panel.add(panel2,BorderLayout.SOUTH);panel.setOpaque(false);contentPane.add(text1,BorderLayout.NORTH);contentPane.add(panel,BorderLayout.CENTER);frame.getLayeredPane().add(picture,new Integer(Integer.MIN_VALUE);Toolkit kit=Too
10、lkit.getDefaultToolkit();Dimension screenSize=kit.getScreenSize();int screenWidth=screenSize.width/2;int screenHeight=screenSize.height/2;int height=this.getHeight();int width=this.getWidth();picture.setBounds(0,0,360,360);(JPanel)contentPane).setOpaque(false);frame.setLocation(screenWidth-width/2,s
11、creenHeight-height/2);frame.setVisible(true);public class insertActionPerformed implements ActionListenerpublic void actionPerformed(ActionEvent e)new Insert().setVisible(true);public class modifyActionPerformed implements ActionListenerpublic void actionPerformed(ActionEvent e)new Modify().setVisib
12、le(true);public class queryActionPerformed implements ActionListenerpublic void actionPerformed(ActionEvent e)new Query().setVisible(true);public class deleteActionPerformed implements ActionListenerpublic void actionPerformed(ActionEvent e)new Delete().setVisible(true);public static void main(Strin
13、g args)new MainFrame();Insert 类类import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class Insert extends JFrameJTextField input1,input2,input3,input4,input5,input6;JLabel label1,label2,label3,label4,label5;JButton button;static Statement st;statictryClass.forName(
14、sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:student);st=con.createStatement();catch(Exception e)ResultSet rs;public Insert()input1=new JTextField(15);input2=new JTextField(15);input3=new JTextField(15);input4=new JTextField(15);input5=new JTextField(15);input6=n
15、ew JTextField(15);JPanel panel=new JPanel();panel.setLayout(new GridLayout(6,2);panel.add(new JLabel(学号),BorderLayout.CENTER);panel.add(input1);panel.add(new JLabel(姓名),BorderLayout.CENTER);panel.add(input2);panel.add(new JLabel(班级),BorderLayout.CENTER);panel.add(input3);panel.add(new JLabel(语文),Bor
16、derLayout.CENTER);panel.add(input4);panel.add(new JLabel(英语);panel.add(input5);panel.add(new JLabel(数学);panel.add(input6);button=new JButton(添 加);button.addActionListener(new mysql();Container container=getContentPane();container.add(panel,BorderLayout.CENTER);container.add(button,BorderLayout.SOUTH
17、);setTitle(添加数据窗口);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);setSize(250,250);Toolkit kit=Toolkit.getDefaultToolkit();Dimension screenSize=kit.getScreenSize();int screenWidth=screenSize.width/2;int screenHeight=screenSize.height/2;int height=this.getHeight();int width=this.getWidth();setLoca
18、tion(screenWidth-width/2,screenHeight-height/2);setVisible(true);class mysql implements ActionListenerpublic void actionPerformed(ActionEvent e)tryString number=input1.getText().trim();String name=input2.getText().trim();String clas=input3.getText().trim();String temp=input4.getText();int chinese=In
19、teger.parseInt(temp);temp=input4.getText();int english=Integer.parseInt(temp);temp=input4.getText();int maths=Integer.parseInt(temp);if(number.equals()|name.equals()|clas.equals()|temp.equals()JOptionPane.showMessageDialog(Insert.this,请重新输入,提示对话框,1);elseString sql=insert into ScoreInfo(ID,name,class
20、,Chinese,English,Maths)values(+number+,+name+,+clas+,+chinese+,+english+,+maths+);st.executeUpdate(sql);JOptionPane.showMessageDialog(Insert.this,数据添加成功,提示对话框,1);input1.setText();input2.setText();input3.setText();input4.setText();input5.setText();input6.setText();catch(Exception ee)Query 类类import ja
21、va.awt.*;import javax.swing.event.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class Query extends JFrame JTextArea show;JButton button1,button2,button3,button4,button5;JTextField field1,field2,field3;JComboBox comoBox;static Statement st;statictryClass.forName(sun.jdbc.od
22、bc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:student);st=con.createStatement();catch(Exception e)public Query()show=new JTextArea(5,10);button1=new JButton(显示所有信息);button1.addActionListener(new Mysql1();Container container=getContentPane();container.setLayout(new BorderLayo
23、ut();JPanel panel=new JPanel();JPanel mainpanel=new JPanel();button2=new JButton(按学号查询);button2.addActionListener(new Mysql2();panel.add(button2);field1=new JTextField(7);panel.add(field1);panel.setVisible(true);mainpanel.add(panel);button3=new JButton(按姓名查询);button3.addActionListener(new Mysql3();p
24、anel.add(button3);field2=new JTextField(6);panel.add(field2);panel.setVisible(true);mainpanel.add(panel);button4=new JButton(按班级查询);button4.addActionListener(new Mysql4();panel.add(button4);field3=new JTextField(6);panel.add(field3);panel.setVisible(true);mainpanel.add(panel);String items=请选择,语文,英语,
25、数学;comoBox=new JComboBox(items);button5=new JButton(按课程名称查询);button5.addActionListener(new Mysql5();panel.add(button5);panel.add(comoBox);panel.setVisible(true);mainpanel.add(panel);panel=new JPanel();panel.add(button1);container.add(mainpanel,BorderLayout.NORTH);container.add(panel,BorderLayout.SOU
26、TH);container.add(new JScrollPane(show),BorderLayout.CENTER);setTitle(查 询 数 据);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);setSize(750,400);Toolkit kit=Toolkit.getDefaultToolkit();Dimension screenSize=kit.getScreenSize();int screenWidth=screenSize.width/2;int screenHeight=screenSize.height/2;i
27、nt height=this.getHeight();int width=this.getWidth();setLocation(screenWidth-width/2,screenHeight-height/2);setVisible(true);class Mysql1 implements ActionListenerpublic void actionPerformed(ActionEvent e)tryString sql=select*from ScoreInfo;ResultSet rs=st.executeQuery(sql);show.setText();姓名show.app
28、end(序号班级语文学号英语数学+n);while(rs.next()show.append(rs.getInt(1)+show.append(rs.getString(2)+););show.append(rs.getString(3)+show.append(rs.getString(4)+show.append(rs.getInt(5)+);););show.append(rs.getInt(6)+show.append(rs.getInt(7)+n););catch(Exception ee)class Mysql2 implements ActionListenerpublic vo
29、id actionPerformed(ActionEvent e)tryString ss=field1.getText().trim();String sql=select*from ScoreInfo where ID=+ss+;ResultSet rs=st.executeQuery(sql);show.setText();姓名show.append(序号班级语文学号英语数学+n);class Mysql3 implements ActionListenerpublic void actionPerformed(ActionEvent e)tryString ss=field2.getT
30、ext().trim();String sql=select*from ScoreInfo where name=+ss+;ResultSet rs=st.executeQuery(sql);show.setText();姓名show.append(序号班级语文学号英语数学+n);while(rs.next()show.append(rs.getInt(1)+show.append(rs.getString(2)+show.append(rs.getString(3)+show.append(rs.getString(4)+show.append(rs.getInt(5)+show.appen
31、d(rs.getInt(6)+show.append(rs.getInt(7)+n);););););););catch(Exception ee)class Mysql4 implements ActionListenerpublic void actionPerformed(ActionEvent e)tryshow.append(rs.getString(3)+show.append(rs.getString(4)+show.append(rs.getInt(5)+show.append(rs.getInt(6)+show.append(rs.getInt(7)+n);););););c
32、atch(Exception ee)class Mysql5 implements ActionListenerpublic void actionPerformed(ActionEvent e)tryString sql=;String ss=comoBox.getSelectedItem().toString();if(ss.equals(语文)sql=select ID,name,class,Chinese from ScoreInfo;show.setText();姓名show.append(序号班级语文+n);学号else if(ss.equals(英语)sql=select ID,
33、name,class,English from ScoreInfo;show.setText();show.append(序号班级英语+n);学号show.append(+i+rs.getString(1)+);););show.append(rs.getString(2)+show.append(rs.getString(3)+show.append(rs.getInt(4)+n);catch(Exception ee)Modify 类类 import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sq
34、l.*;public class Modify extends JFrameJTextField input1,input2,input3,input4,input5,input6;JLabel label1,label2,label3,label4,label5;JButton button;static Statement st;statictryClass.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:student);st=con.createState
35、ment();catch(Exception e)ResultSet rs;public Modify()input1=new JTextField(15);input2=new JTextField(15);input3=new JTextField(15);input4=new JTextField(15);input5=new JTextField(15);input6=new JTextField(15);JPanel panel=new JPanel();panel.setLayout(new GridLayout(6,2);panel.add(new JLabel(学号);pane
36、l.add(input1);panel.add(new JLabel(姓名);panel.add(input2);panel.add(new JLabel(班级);panel.add(input3);panel.add(new JLabel(语文);panel.add(input4);panel.add(new JLabel(英语);panel.add(input5);panel.add(new JLabel(数学);panel.add(input6);button=new JButton(修 改);button.addActionListener(new mysql();Container
37、container=getContentPane();container.add(panel,BorderLayout.CENTER);container.add(button,BorderLayout.SOUTH);setTitle(修改数据窗口);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);setSize(300,150);Toolkit kit=Toolkit.getDefaultToolkit();Dimension screenSize=kit.getScreenSize();int screenWidth=screenSize
38、.width/2;int screenHeight=screenSize.height/2;int height=this.getHeight();int width=this.getWidth();setLocation(screenWidth-width/2,screenHeight-height/2);setVisible(true);class mysql implements ActionListenerpublic void actionPerformed(ActionEvent e)tryString number=input1.getText().trim();String n
39、ame=input2.getText().trim();String clas=input3.getText().trim();String temp=input4.getText();int chinese=Integer.parseInt(temp);temp=input4.getText();int english=Integer.parseInt(temp);temp=input4.getText();int maths=Integer.parseInt(temp);if(number.equals()JOptionPane.showMessageDialog(Modify.this,
40、学号不能为空!,提示对话框,1);elsetryStringsql=updateScoreInfoset name=+name+,class=+clas+,Chinese=+chinese+,English=+english+,Maths=+maths+where ID=+number+;st.executeUpdate(sql);JOptionPane.showMessageDialog(Modify.this,数据修改成功,提示对话框,1);input1.setText();input2.setText();input3.setText();input4.setText();input5.
41、setText();input6.setText();catch(Exception ee)JOptionPane.showMessageDialog(Modify.this,请确认需要修改的 学号是否存在,提示对话框,1);System.out.println(ee);catch(Exception eee)System.out.println(eee);import javax.swing.*;import java.sql.*;public class Delete extends JFrameJButton search;JTextField input;JTextArea show;
42、Connection con;Statement st;public Delete()JPanel p=new JPanel();search=new JButton(删除);input=new JTextField(10);show=new JTextArea(6,43);p.add(new JLabel(输入要删除的学号);p.add(input);p.add(search);setTitle(删除数据窗口);search.addActionListener(new Mysql();show.setEditable(false);add(p,BorderLayout.NORTH);add(
43、show,BorderLayout.CENTER);setSize(400,150);Toolkit kit=Toolkit.getDefaultToolkit();Dimension screenSize=kit.getScreenSize();int screenWidth=screenSize.width/2;int screenHeight=screenSize.height/2;int height=this.getHeight();int width=this.getWidth();setLocation(screenWidth-width/2,screenHeight-heigh
44、t/2);setVisible(true);validate();addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)dispose(););class Mysql implements ActionListenerpublic void actionPerformed(ActionEvent ee)tryClass.forName(sun.jdbc.odbc.JdbcOdbcDriver);catch(ClassNotFoundException eee)System.out.println
45、(+eee);tryString ss=input.getText().trim();con=DriverManager.getConnection(jdbc:odbc:student);st=con.createStatement();String sql=select*from ScoreInfo where ID=+ss+;show.setText(sql);ResultSet rs=st.executeQuery(sql);while(rs.next()Stringnumber=rs.getString(ID);String String intname=rs.getString(na
46、me);clas=rs.getString(class);chinese=rs.getInt(Chinese);intenglish=rs.getInt(English);intmath=rs.getInt(Maths);show.setText(你删除了:n);show.append(学号:+number+n姓名:+name+n班级:+clas+n语文+chinese+n英语+english+n数学+math);show.append(n);sql=delete*from ScoreInfo where ID=+ss+;st.executeUpdate(sql);con.close();catch(SQLException e)show.setText(无此条记录);System.out.println(e);