用java编写的学生成绩管理系统代码

合集下载

用java写的一个简单的学生成绩管理系统(含代码)

用java写的一个简单的学生成绩管理系统(含代码)

用java写的一个简单的学生成绩管理系统一.简洁的需求描述学生成绩管理系统(以下简称系统)为教师和学生的信息交流提供了一个统一的平台,方便了教师对成绩的管理,学生对于成绩的查询等1.教师可以通过系统查询所授课程的信息以及课程所对应的学生的信息;教师通过系统管理学生分数信息,包括查询,输入,修改学生成绩。

2.学生用户仅仅拥有查询功能,查询的信息包括所选修课程信息和分数信息。

系统用例图:用例图解释系统功能大致上分为分数管理,课程管理,个人信息查询,分数查询四大块。

其中教师用户使用分数管理和课程管理功能,学生用户使用个人信息查询和分数查询功能。

细分来,分数管理指的是分数的录入,更新,查询;课程管理包括所授课程查询,课程信息录入,修改等;个人信息查询针对学生而言,包括姓名,学号,班级等;分数查询则指的是某一学期所有课程的分数信息的查询。

二.简单的设计说明2.1系统类图2009-04-12 18:38三。

简单的数据库设计ER图:数据库详细设计说明:1).数据库说明数据库取名为score_manage_system其中有五个表,分别为:TEACHER(TNO ,TNAME,SEX,TITLE,PASSWORD)..............教师信息表STUDENT (SNO,SNAME,SEX,CLASS,PASSWORD) .................学生信息表COURSE(CNO,CNAME,CXUEFEN,HOUR)..............................课程信息表TEACH(TNO,CNO)............................................................................教师授课信息表STUDY(SNO,CNO,SCORE)...........................................................学生选课信息表2009-04-12 18:412).字段说明3)TEACHER字段类型主码外码说明TNO CHAR(20) √ √ 教师代码TNAME CHAR(10) 教师姓名SEX CHAR(1) 教师性别TITLE CHAR(10) 职称PASSWORD CHAR(20) 登录密码STUDENT字段类型主码外码说明SNO CHAR(20) √ √ 学号SNAME CHAR(10) 学生姓名SEX CHAR(2) 性别CLASS CHAR(5) 班级PASSWORD CHAR(20) 登录密码DEPARTMENT CHAR(20) 学生所属院系SCHOOL CHAR(20) 学生所属学校COURSE字段类型主码外码说明CNO CHAR(20) √ √ 课程代码CNAME CHAR(10) 课程名称XUEFEN int 学分,取值大于0小于10HOUR int 学时,大于等于0YEAR CHAR(5) 学年TERM CHAR(1) 学分TEACH字段类型主码外码说明TNO CHAR(20) √教师代码CNO CHAR(20) √课程代码STUDY字段类型主码外码说明SNO CHAR(20) √学号CNO CHAR(20) √课程代码SCORE DOUBLE 分数,0--1003).建表语句TEACHER建表语句:create table TEACHER(TNO char(20) not null, TNAME char(10) not null, SEX char(1) not null,TITLE char(10) not null, PASSWORD char(20) not null, primary key (TNO),check(SEX in('男','女')));STUDENT建表语句:create table STUDENT(SNO char(20) not null, SNAME char(10) not null, SEX char(2) not null,CLASS char(5) not null, PASSWORD char(20) not null,DEPARTMENT char(20) not null,SCHOOL char(20) not null, primary key (SNO),check(SEX in('男','女')));COURSE建表语句:create table COURSE(CNO char(20) not null, CNAME char(10) not null, XUEFEN int not null, HOUR int not null, YEAR char(5) not null,TERM char(1) not null,primary key (CNO),check(XUEFEN > 0 and XUEFEN < 10 and HOUR >= 0 ));TEACH建表语句:create table TEACH(TNO char(20) not null, CNO char(20) not null, primary key (TNO, CNO)foreign key(TNO,CNO)REFERENCES TEACHER COURSE ,foreign key(CNO)REFERENCES COURSE);alter table TEACHadd constraint FK_TEACH_REFERENCE_TEACHER foreign key (TNO) references TEACHER (TNO)on update restricton delete restrict;alter table TEACHadd constraint FK_TEACH_REFERENCE_COURSE foreign key (CNO) references COURSE (CNO)on update restricton delete restrict;2009-04-12 18:41STUDY建表语句:create table STUDY(SNO char(20) not null, CNO char(20) not null,SCORE double ,primary key (SNO, CNO),check(SCORE >=0 and SCORE <= 100));alter table STUDYadd constraint FK_STUDY_REFERENCE_COURSE foreign key (CNO) references COURSE (CNO)on update restricton delete restrict;alter table STUDYadd constraint FK_STUDY_REFERENCE_STUDENT foreign key (SNO) references STUDENT (SNO)on update restricton delete restrict;2009-04-12 18:42四。

用java写的一个简单的学生成绩管理系统(含代码)

用java写的一个简单的学生成绩管理系统(含代码)

用java写的一个简单的学生成绩管理系统一.简洁的需求描述学生成绩管理系统(以下简称系统)为教师和学生的信息交流提供了一个统一的平台,方便了教师对成绩的管理,学生对于成绩的查询等1.教师可以通过系统查询所授课程的信息以及课程所对应的学生的信息;教师通过系统管理学生分数信息,包括查询,输入,修改学生成绩。

2.学生用户仅仅拥有查询功能,查询的信息包括所选修课程信息和分数信息。

系统用例图:用例图解释系统功能大致上分为分数管理,课程管理,个人信息查询,分数查询四大块。

其中教师用户使用分数管理和课程管理功能,学生用户使用个人信息查询和分数查询功能。

细分来,分数管理指的是分数的录入,更新,查询;课程管理包括所授课程查询,课程信息录入,修改等;个人信息查询针对学生而言,包括姓名,学号,班级等;分数查询则指的是某一学期所有课程的分数信息的查询。

二.简单的设计说明2.1系统类图2009-04-12 18:38三。

简单的数据库设计ER图:数据库详细设计说明:1).数据库说明数据库取名为score_manage_system其中有五个表,分别为:TEACHER(TNO ,TNAME,SEX,TITLE,PASSWORD)..............教师信息表STUDENT (SNO,SNAME,SEX,CLASS,PASSWORD) .................学生信息表COURSE(CNO,CNAME,CXUEFEN,HOUR)..............................课程信息表TEACH(TNO,CNO)............................................................................教师授课信息表STUDY(SNO,CNO,SCORE)...........................................................学生选课信息表2009-04-12 18:412).字段说明3)TEACHER字段类型主码外码说明TNO CHAR(20) √ √ 教师代码TNAME CHAR(10) 教师姓名SEX CHAR(1) 教师性别TITLE CHAR(10) 职称PASSWORD CHAR(20) 登录密码STUDENT字段类型主码外码说明SNO CHAR(20) √ √ 学号SNAME CHAR(10) 学生姓名SEX CHAR(2) 性别CLASS CHAR(5) 班级PASSWORD CHAR(20) 登录密码DEPARTMENT CHAR(20) 学生所属院系SCHOOL CHAR(20) 学生所属学校COURSE字段类型主码外码说明CNO CHAR(20) √ √ 课程代码CNAME CHAR(10) 课程名称XUEFEN int 学分,取值大于0小于10HOUR int 学时,大于等于0YEAR CHAR(5) 学年TERM CHAR(1) 学分TEACH字段类型主码外码说明TNO CHAR(20) √教师代码CNO CHAR(20) √课程代码STUDY字段类型主码外码说明SNO CHAR(20) √学号CNO CHAR(20) √课程代码SCORE DOUBLE 分数,0--1003).建表语句TEACHER建表语句:create table TEACHER(TNO char(20) not null, TNAME char(10) not null, SEX char(1) not null,TITLE char(10) not null, PASSWORD char(20) not null, primary key (TNO),check(SEX in('男','女')));STUDENT建表语句:create table STUDENT(SNO char(20) not null, SNAME char(10) not null, SEX char(2) not null,CLASS char(5) not null, PASSWORD char(20) not null,DEPARTMENT char(20) not null,SCHOOL char(20) not null, primary key (SNO),check(SEX in('男','女')));COURSE建表语句:create table COURSE(CNO char(20) not null, CNAME char(10) not null, XUEFEN int not null, HOUR int not null, YEAR char(5) not null,TERM char(1) not null,primary key (CNO),check(XUEFEN > 0 and XUEFEN < 10 and HOUR >= 0 ));TEACH建表语句:create table TEACH(TNO char(20) not null, CNO char(20) not null, primary key (TNO, CNO)foreign key(TNO,CNO)REFERENCES TEACHER COURSE ,foreign key(CNO)REFERENCES COURSE);alter table TEACHadd constraint FK_TEACH_REFERENCE_TEACHER foreign key (TNO) references TEACHER (TNO)on update restricton delete restrict;alter table TEACHadd constraint FK_TEACH_REFERENCE_COURSE foreign key (CNO) references COURSE (CNO)on update restricton delete restrict;2009-04-12 18:41STUDY建表语句:create table STUDY(SNO char(20) not null, CNO char(20) not null,SCORE double ,primary key (SNO, CNO),check(SCORE >=0 and SCORE <= 100));alter table STUDYadd constraint FK_STUDY_REFERENCE_COURSE foreign key (CNO) references COURSE (CNO)on update restricton delete restrict;alter table STUDYadd constraint FK_STUDY_REFERENCE_STUDENT foreign key (SNO) references STUDENT (SNO)on update restricton delete restrict;2009-04-12 18:42四。

基于JAVA的学生成绩管理系统源代码

基于JAVA的学生成绩管理系统源代码
butt on 2=new Butt on(“删除");
butt on 3=new Butt on(“修改");
butt on 4=new Butto n("添加");
tuichu=new Button("退岀");
p1=new Pan el();
p2=new Pan el();
p3=new Pan el();
Button butt on 1,butt on 2,butt on 3,butto n4,tuichu;
Pan el p1, p2,p3;
Label l1,l2,l3;
TextField a1,a2;
Box b1,b2,b3,b4,b5;
ss s;
zhuchuangkouO{("登陆");
(this);
(l1);
(b5);
add( p1,;
add( p2,;
add( p3,;
addWi ndowListe ner(new Win dowAda pter(){
p ublic void wi ndowClosi ng(Wi ndowEve nt e){ dis pose();
}
});
setBackgrou nd;
add( p2,;
add( p3,;
addWi ndowListe ner(new Win dowAda pter(){
p ublic void win dowClosi ng(Wi ndowEve nt e){
dis pose();
});
setBackgrou nd;
setBou nds(10, 10, 1000, 500);

java学生成绩管理系统源码

java学生成绩管理系统源码

文件addmessage.java代码:import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;class addmessage extends JFrame implements ActionListener{ JTextField t1,t2,t3,t4,t5;JTable table;JButton but1;JLabel lab1,lab2,lab3,lab4,lab5;JPanel p1;addmessage(){super("增加");setBounds(350,100,470,400);setLayout(new GridLayout(1,1,10,10));p1=new JPanel();lab1=new JLabel("学号"); t1=new JTextField(10);lab2=new JLabel("姓名"); t2=new JTextField(10);lab3=new JLabel("课程名"); t3=new JTextField(10);lab4=new JLabel("状态"); t4=new JTextField(10);lab5=new JLabel("成绩"); t5=new JTextField(10);but1=new JButton("添加");but1.addActionListener(this);p1.add(lab1);p1.add(t1);p1.add(lab2);p1.add(t2);p1.add(lab3);p1.add(t3);p1.add(lab4);p1.add(t4);p1.add(lab5);p1.add(t5);p1.add(but1);add(p1);setVisible(true);}public void actionPerformed(ActionEvent e){int i=0 ;String sql1=null,sql2=null,update=null;String url="jdbc:mysql://localhost:3306/学生成绩系统";Connection con;Statement stmt;try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ng.ClassNotFoundException e1){System.err.println("ClassNotFoundException:"+e1.getMessage());}if(e.getSource()==but1){ //添加-------------------try{con=DriverManager.getConnection(url,"root","123");stmt=con.createStatement();sql1="INSERT INTO 学生成绩表VALUES ('"+t1.getText()+"','"+t2.getText()+"','"+t3.getText()+"','"+t4.getText()+"','"+t5.getText()+"')";String num1=t1.getText();String num2=t1.getText();String sele="select * from 学生成绩表where 学号='"+num1+"' and 课程名='"+num2+"'";ResultSet rs=stmt.executeQuery(sele);if(rs.next()){JOptionPane.showMessageDialog(this, "已有该条记录,请核实!");}else{stmt.executeUpdate(sql1);JOptionPane.showMessageDialog(this, "添加成功!");}t1.setText("");t2.setText("");t3.setText("");t4.setText("");t5.setText("");stmt.close();con.close();}catch(SQLException ex){System.err.println("SQLException:"+ex.getMessage());}}}}文件deletemessage.java代码import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;class deletemessage extends JFrame implements ActionListener{ JTextField t1,t2,t3;JTable table;JButton but1;JLabel lab1,lab2,lab3;JPanel p1;deletemessage(){super("删除");setBounds(350,100,470,400);setLayout(new GridLayout(1,1,10,10));p1=new JPanel();lab1=new JLabel("学号"); t1=new JTextField(10);lab2=new JLabel("姓名"); t2=new JTextField(10);lab3=new JLabel("课程名"); t3=new JTextField(10);but1=new JButton("删除");but1.addActionListener(this);p1.add(lab1);p1.add(t1);p1.add(lab2);p1.add(t2);p1.add(lab3);p1.add(t3);p1.add(but1);add(p1);setVisible(true);}public void actionPerformed(ActionEvent e){String sql1=null,sql2=null;String url="jdbc:mysql://localhost:3306/学生成绩系统";Connection con;Statement stmt;try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ng.ClassNotFoundException e1){System.err.println("ClassNotFoundException:"+e1.getMessage());}if(e.getSource()==but1){ //删除----------------------------try{String num1=t1.getText();String num2=t2.getText();String num3=t3.getText();sql2="delete from 学生成绩表where 学号='"+num1+"'and 课程名='"+num3+"'";con=DriverManager.getConnection(url,"root","123");stmt=con.createStatement();sql1="select * from 学生成绩表where 学号='"+num1+"' and 姓名='"+num2+"' and 课程名='"+num3+"'";ResultSet rs=stmt.executeQuery(sql1);if(rs.next()){stmt.executeUpdate(sql2);JOptionPane.showMessageDialog(this, "删除成功!");}else{JOptionPane.showMessageDialog(this, "没有此条记录!请重新输入");}t1.setText("");stmt.close();con.close();}catch(SQLException ex){System.err.println("SQLException:"+ex.getMessage());}}}}文件entry.java代码import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.*;class entry extends JFrame implements ActionListener{ int flag=1;String user,pass;JPanel pa;JLabel lab1,lab2;JTextField tf1;JPasswordField tf2;JButton btu1,btu2;JPanel pa1,pa2,pa4;entry(){super("学生成绩管理系统");setBounds(400,200,400,300);GridBagLayout gbL=new GridBagLayout();GridBagConstraints gbc=new GridBagConstraints();setLayout(gbL);gbc.fill=GridBagConstraints.HORIZONTAL;gbc.anchor=GridBagConstraints.CENTER;lab1=new JLabel("请输入帐号");lab2=new JLabel("请输入密码");tf2=new JPasswordField(10);tf2.setEchoChar('*');tf1=new JTextField(10);tf1.addActionListener(this);pa1=new JPanel();pa1.add(lab1);pa1.add(tf1);gbc.gridx=1;gbc.gridy=1;gbc.insets=new Insets(2,5,0,5);gbL.setConstraints(pa1,gbc);add(pa1);tf2.addActionListener(this);pa2=new JPanel();pa2.add(lab2);pa2.add(tf2);gbc.gridx=1;gbc.gridy=2;gbc.insets=new Insets(2,5,2,5);gbL.setConstraints(pa2,gbc);add(pa2);btu1=new JButton("确定");btu1.addActionListener(this);btu2=new JButton("退出");btu2.addActionListener(this);pa4=new JPanel();pa4.add(btu1);pa4.add(btu2);gbc.gridx=1;gbc.gridy=4;gbc.insets=new Insets(2,5,2,5);gbL.setConstraints(pa4,gbc);add(pa4);}public void actionPerformed(ActionEvent e){loginsure ls;if(e.getSource()==btu1){user=tf1.getText();pass=tf2.getText();try{ls=new loginsure(user,pass);this.setVisible(false);}catch (SQLException e1){e1.printStackTrace();}catch (ClassNotFoundException e1){e1.printStackTrace();}}if(e.getSource()==btu2){dispose();System.exit(0);}}}class loginsure{int i=0;String name=null,pwd=null, ustype=null;public loginsure(String s,String a) throws SQLException,ClassNotFoundException{ String driver ="org.gjt.mm.mysql.Driver";Class.forName(driver);String URL = "jdbc:mysql://localhost:3306/学生成绩系统";Connection conn = DriverManager.getConnection(URL,"root","123");Statement stmt=conn.createStatement();ResultSet rs = stmt.executeQuery("select * from 用户管理表");while (rs.next()){name=rs.getString("用户名").trim();pwd=rs.getString("密码").trim();ustype=rs.getString("权限组").trim();if (s.equals(name)&&a.equals(pwd)){i=1;if(ustype.trim().equals("管理员")){teacher tea=new teacher();tea.setVisible(true);}if(ustype.trim().equals("学生")){student stu=new student(name);stu.setVisible(true);}}}if(i==0)JOptionPane.showMessageDialog(null, "用户名或者密码错误", "警告",JOptionPane.W ARNING_MESSAGE);stmt.close();conn.close();}}文件inquiry.java代码import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;class inquiry extends JFrame implements ActionListener{ JTextField t1;JTable table;JButton but1;JLabel lab1;JPanel p1;JTable table1=null;DefaultTableModel demod1=null;String n[]={"课程名","状态","成绩"};String [][]data=new String[0][0];String No;inquiry(String no){super("成绩");No=no;setBounds(350,100,470,400);p1=new JPanel();lab1=new JLabel("课程名"); t1=new JTextField(10);but1=new JButton("查询成绩");but1.addActionListener(this);p1.add(lab1);p1.add(t1);p1.add(but1);demod1=new DefaultTableModel(data,n);table1=new JTable(demod1);JScrollPane s1=new JScrollPane(table1);p1.add(s1);add(p1);setVisible(true);}public void actionPerformed(ActionEvent e){int i=0;String sql1;String url="jdbc:mysql://localhost:3306/学生成绩系统";Connection con;Statement stmt;try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ng.ClassNotFoundException e1){System.err.println("ClassNotFoundException:"+e1.getMessage());}if(e.getSource()==but1){try{String num=t1.getText();sql1="select * from 学生成绩表where 学号='"+No+"'";if(!num.equals("")){sql1="select * from 学生成绩表where 课程名='"+num+"'and 学号='"+No+"'";}con=DriverManager.getConnection(url,"root","123");stmt=con.createStatement();ResultSet rs=stmt.executeQuery(sql1);removeAllRecord();while(rs.next()){Vector data=new Vector();data.addElement(rs.getString(3));data.addElement(rs.getString(4));data.addElement(rs.getString(5));demod1.addRow(data);i=1;}if(i==0){JOptionPane.showMessageDialog(this, "没有此课程!请重新输入");}table1.revalidate();t1.setText("");stmt.close();con.close();}catch(SQLException ex){System.err.println("SQLException:"+ex.getMessage());}}}public void removeAllRecord(){//将界面上的所有记录清空int rowcount;while(true){//删除所有存在的行rowcount = demod1.getRowCount()-1;if(rowcount >= 0){demod1.removeRow(rowcount);demod1.setRowCount(rowcount);}elsebreak;}}}import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;public class main{public static void main(String args[]){entry ent=new entry();ent.setVisible(true);ent.setResizable(false);}}import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;class record extends JFrame implements ActionListener{ JTextField t1;TextArea t;JButton but1;JLabel L1;JPanel p1;JTable table1=null;DefaultTableModel demod1=null;String n[]={"平均成绩","优秀","良好","不及格"};String [][]data=new String[0][0];public record(){super("统计");setBounds(350,30,470,610);setLayout(new GridLayout(1,1,10,10));p1=new JPanel();L1=new JLabel("课程名");but1=new JButton("查询");but1.addActionListener(this);t1=new JTextField(10);p1.add(L1);p1.add(t1);p1.add(but1);demod1=new DefaultTableModel(data,n);table1=new JTable(demod1);JScrollPane s1=new JScrollPane(table1);p1.add(s1);add(p1);setVisible(true);}public void actionPerformed(ActionEvent e){int i=0;String sql1;String sql2;String url="jdbc:mysql://localhost:3306/学生成绩系统";Connection con;Statement stmt;try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ng.ClassNotFoundException e1){System.err.println("ClassNotFoundException:"+e1.getMessage());}if(e.getSource()==but1){try{String num1=t1.getText();if(num1.equals("")){JOptionPane.showMessageDialog(this, "学号不能为空","请输入学号!",JOptionPane.W ARNING_MESSAGE);}else{sql1="select * from 学生成绩表where 学号='"+num1+"'";sql1="select avg(成绩) from 学生成绩表where 课程名='"+num1+"'";sql2="select count(*) from 学生成绩表where 课程名='"+num1+"' and 成绩>=90";con=DriverManager.getConnection(url,"root","123");stmt=con.createStatement();ResultSet rs=stmt.executeQuery(sql1);removeAllRecord();while(rs.next()){Vector data=new Vector();data.addElement(rs.getInt(1));/*data.addElement(rs.getString(3));data.addElement(rs.getString(4));data.addElement(rs.getString(5));*/demod1.addRow(data);i=1;}rs=stmt.executeQuery(sql2);while(rs.next()){int n = rs.getInt(1);System.out.println(n);}if(i==0){JOptionPane.showMessageDialog(this, "没有此条记录!请重新输入");}table1.revalidate();t1.setText("");stmt.close();con.close();}}catch(SQLException ex){System.err.println("SQLException:"+ex.getMessage());}}}public void removeAllRecord(){//将界面上的所有记录清空int rowcount;while(true){//删除所有存在的行rowcount = demod1.getRowCount()-1;if(rowcount >= 0){demod1.removeRow(rowcount);demod1.setRowCount(rowcount);}elsebreak;}}}文件revise.java代码import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;class revise extends JFrame implements ActionListener{ JTextField t1,t2,t3,t4,t5;JTable table;JButton but1;JLabel lab1,lab2,lab3,lab4,lab5;JPanel p1;int n=0;revise(){super("修改");setBounds(350,100,470,400);setLayout(new GridLayout(1,1,10,10));p1=new JPanel();lab1=new JLabel("学号"); t1=new JTextField(10);lab2=new JLabel("姓名"); t2=new JTextField(10);lab3=new JLabel("课程名"); t3=new JTextField(10);lab4=new JLabel("状态"); t4=new JTextField(10);lab5=new JLabel("成绩"); t5=new JTextField(10);but1=new JButton("修改");but1.addActionListener(this);p1.add(lab1);p1.add(t1);p1.add(lab2);p1.add(t2);p1.add(lab3);p1.add(t3);p1.add(lab4);p1.add(t4);p1.add(lab5);p1.add(t5);p1.add(but1);add(p1);setVisible(true);}public void actionPerformed(ActionEvent e){String sql1=null,update=null;String url="jdbc:mysql://localhost:3306/学生成绩系统";Connection con;Statement stmt;try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ng.ClassNotFoundException e1){System.err.println("ClassNotFoundException:"+e1.getMessage());}if(e.getSource()==but1){ //修改---------------------------try{String num1=t3.getText();String num2=t1.getText();//String num3=t5.getText();n= Integer.valueOf(t5.getText()).intValue();System.out.print(n);con=DriverManager.getConnection(url,"root","123");stmt=con.createStatement();sql1="select * from 学生成绩表where 学号='"+num2+"' and 课程名='"+num1+"'";update="update 学生成绩表set 课程名='"+t3.getText()+"',状态='"+t4.getText()+"',成绩='"+n+"' where 学号='"+num2+"'";ResultSet rs=stmt.executeQuery(sql1);if(rs.next()){stmt.executeUpdate(update);JOptionPane.showMessageDialog(this, "修改成功!");}else{JOptionPane.showMessageDialog(this, "没有此条记录!请重新输入");}t1.setText("");t2.setText("");t3.setText("");t4.setText("");t5.setText("");stmt.close();con.close();}catch(SQLException ex){System.err.println("SQLException:"+ex.getMessage());}}}}import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;class student extends JFrame implements ActionListener{ inquiry cho;JMenuBar mb;JMenu m1;JMenuItem mt1,mt2;String No;Icon icon;JLabel lab;student(String no){super("学生");icon=new ImageIcon("123.jpg");lab=new JLabel(icon);add(lab);No=no;setBounds(130,10,800,500);JMenuBar mb=new JMenuBar();setJMenuBar(mb);m1=new JMenu("操作");mt1=new JMenuItem("查询成绩");mt2=new JMenuItem("退出");m1.add(mt1);mt1.addActionListener(this);m1.addSeparator();m1.add(mt2);mt2.addActionListener(this);m1.addActionListener(this);mb.add(m1);}public void actionPerformed(ActionEvent e){if(e.getSource()==mt1)cho=new inquiry(No);if(e.getSource()==mt2)dispose();}}import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;class teacher extends JFrame implements ActionListener{ addmessage add;deletemessage delete;revise re;user use;record rec;MenuBar mb;Menu m1;MenuItem mt1,mt2,mt3,mt4,mt5,mt6;Icon icon;JLabel lab;teacher(){super("管理员");setBounds(130,10,800,500);MenuBar mb=new MenuBar();setMenuBar(mb);m1=new Menu("操作");mt1=new MenuItem("增加");mt2=new MenuItem("删除");mt3=new MenuItem("修改");mt4=new MenuItem("查询");mt5=new MenuItem("统计");mt6 = new MenuItem("退出");icon=new ImageIcon("123.jpg");lab=new JLabel(icon);add(lab);mt1.addActionListener(this);m1.add(mt1);mt2.addActionListener(this);m1.add(mt2);mt3.addActionListener(this);m1.add(mt3);mt4.addActionListener(this);m1.add(mt4);mt5.addActionListener(this);m1.add(mt5);m1.addSeparator();mt6.addActionListener(this);m1.add(mt6);m1.addActionListener(this);mb.add(m1);}public void actionPerformed(ActionEvent e){if(e.getSource()==mt1)add=new addmessage();if(e.getSource()==mt2)delete=new deletemessage();if(e.getSource()==mt3)re=new revise();if(e.getSource()==mt4)use=new user();if(e.getSource()==mt5)rec=new record();if(e.getSource()==mt6)dispose();}}文件user.java代码import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;class user extends JFrame implements ActionListener{ JTextField t1,t2;TextArea t;JButton but1;JLabel L1,L2;JPanel p1;JTable table1=null;DefaultTableModel demod1=null;String n[]={"姓名","课程名","状态","成绩"};String [][]data=new String[0][0];public user(){super("查询");setBounds(350,30,470,610);setLayout(new GridLayout(1,1,10,10));p1=new JPanel();L1=new JLabel("学号");L2=new JLabel("课程名");but1=new JButton("查询");but1.addActionListener(this);t1=new JTextField(10);t2=new JTextField(10);p1.add(L1);p1.add(t1);p1.add(L2);p1.add(t2);p1.add(but1);demod1=new DefaultTableModel(data,n);table1=new JTable(demod1);JScrollPane s1=new JScrollPane(table1);p1.add(s1);add(p1);setVisible(true);}public void actionPerformed(ActionEvent e){int i=0;String sql1;String url="jdbc:mysql://localhost:3306/学生成绩系统";Connection con;Statement stmt;try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ng.ClassNotFoundException e1){System.err.println("ClassNotFoundException:"+e1.getMessage());}if(e.getSource()==but1){try{String num1=t1.getText();String num2=t2.getText();if(num1.equals("")){JOptionPane.showMessageDialog(this, "学号不能为空","请输入学号!",JOptionPane.W ARNING_MESSAGE);}else{sql1="select * from 学生成绩表where 学号='"+num1+"'";if(!num2.equals("")){sql1="select * from 学生成绩表where 课程名='"+num2+"'and 学号='"+num1+"'";}con=DriverManager.getConnection(url,"root","123");stmt=con.createStatement();ResultSet rs=stmt.executeQuery(sql1);removeAllRecord();while(rs.next()){Vector data=new Vector();data.addElement(rs.getString(2));data.addElement(rs.getString(3));data.addElement(rs.getString(4));data.addElement(rs.getString(5));demod1.addRow(data);i=1;}if(i==0){JOptionPane.showMessageDialog(this, "没有此条记录!请重新输入");}table1.revalidate();t1.setText("");stmt.close();con.close();}}catch(SQLException ex){System.err.println("SQLException:"+ex.getMessage());}}}public void removeAllRecord(){//将界面上的所有记录清空int rowcount;while(true){//删除所有存在的行rowcount = demod1.getRowCount()-1;if(rowcount >= 0){demod1.removeRow(rowcount);demod1.setRowCount(rowcount);}elsebreak;}}}附件sql语句create table 用户管理表(用户名varchar(25),密码varchar(15),权限组varchar(15))insert into 用户管理表values('01','01','学生')insert into 用户管理表values('admin','admin','管理员') select * from 用户管理表create table 学生成绩表(学号varchar(25),姓名varchar(15),课程名varchar(25),状态varchar(5),成绩int(11))insert into 学生成绩表values('01','朱亮','数据库','通过','88') insert into 学生成绩表values('02','张三','数据库','未通过','55') select * from 学生信息管理表。

Java语言学生成绩管理系统(含源代码)

Java语言学生成绩管理系统(含源代码)

Java语言学生成绩管理系统(含源代码)
简介
该文档介绍了一个用Java语言编写的学生成绩管理系统,包括系统的功能和使用方法。

功能
该系统具有以下功能:
- 学生信息管理:包括学生的姓名、学号、性别等基本信息的录入和管理。

- 成绩录入和统计:学生的各科成绩可以通过系统录入,并且可以进行成绩统计和分析。

- 成绩查询和打印:通过学号或姓名可以查询学生的成绩,并且可以将成绩单以打印的形式输出。

使用方法
- 打开终端或命令行界面,输入以下命令克隆代码库:
git clone <代码库地址>
- 导入项目到Java开发工具中。

2. 编译和运行:
- 在Java开发工具中,找到项目的入口文件或主类。

- 点击运行按钮或使用快捷键进行编译和运行。

3. 使用系统:
- 在系统中选择相应的功能,如学生信息管理、成绩录入和统计、成绩查询和打印等。

- 根据系统的提示,进行相应的操作和输入。

- 根据需要,可以多次使用系统的各个功能。

注意事项
- 该系统仅用于学生管理和成绩统计,不涉及其他法律问题和敏感信息。

- 如需修改或添加系统功能,请参考源代码进行相应的开发和调整。

java学生成绩管理系统源码

java学生成绩管理系统源码

文件addmessage.java代码:import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;class addmessage extends JFrame implements ActionListener{ JTextField t1,t2,t3,t4,t5;JTable table;JButton but1;JLabel lab1,lab2,lab3,lab4,lab5;JPanel p1;addmessage(){super("增加");setBounds(350,100,470,400);setLayout(new GridLayout(1,1,10,10));p1=new JPanel();lab1=new JLabel("学号"); t1=new JTextField(10);lab2=new JLabel("姓名"); t2=new JTextField(10);lab3=new JLabel("课程名"); t3=new JTextField(10);lab4=new JLabel("状态"); t4=new JTextField(10);lab5=new JLabel("成绩"); t5=new JTextField(10);but1=new JButton("添加");but1.addActionListener(this);p1.add(lab1);p1.add(t1);p1.add(lab2);p1.add(t2);p1.add(lab3);p1.add(t3);p1.add(lab4);p1.add(t4);p1.add(lab5);p1.add(t5);p1.add(but1);add(p1);setVisible(true);}public void actionPerformed(ActionEvent e){int i=0 ;String sql1=null,sql2=null,update=null;String url="jdbc:mysql://localhost:3306/学生成绩系统";Connection con;Statement stmt;try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ng.ClassNotFoundException e1){System.err.println("ClassNotFoundException:"+e1.getMessage());}if(e.getSource()==but1){ //添加-------------------try{con=DriverManager.getConnection(url,"root","123");stmt=con.createStatement();sql1="INSERT INTO 学生成绩表VALUES ('"+t1.getText()+"','"+t2.getText()+"','"+t3.getText()+"','"+t4.getText()+"','"+t5.getText()+"')";String num1=t1.getText();String num2=t1.getText();String sele="select * from 学生成绩表where 学号='"+num1+"' and 课程名='"+num2+"'";ResultSet rs=stmt.executeQuery(sele);if(rs.next()){JOptionPane.showMessageDialog(this, "已有该条记录,请核实!");}else{stmt.executeUpdate(sql1);JOptionPane.showMessageDialog(this, "添加成功!");}t1.setText("");t2.setText("");t3.setText("");t4.setText("");t5.setText("");stmt.close();con.close();}catch(SQLException ex){System.err.println("SQLException:"+ex.getMessage());}}}}文件deletemessage.java代码import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;class deletemessage extends JFrame implements ActionListener{ JTextField t1,t2,t3;JTable table;JButton but1;JLabel lab1,lab2,lab3;JPanel p1;deletemessage(){super("删除");setBounds(350,100,470,400);setLayout(new GridLayout(1,1,10,10));p1=new JPanel();lab1=new JLabel("学号"); t1=new JTextField(10);lab2=new JLabel("姓名"); t2=new JTextField(10);lab3=new JLabel("课程名"); t3=new JTextField(10);but1=new JButton("删除");but1.addActionListener(this);p1.add(lab1);p1.add(t1);p1.add(lab2);p1.add(t2);p1.add(lab3);p1.add(t3);p1.add(but1);add(p1);setVisible(true);}public void actionPerformed(ActionEvent e){String sql1=null,sql2=null;String url="jdbc:mysql://localhost:3306/学生成绩系统";Connection con;Statement stmt;try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ng.ClassNotFoundException e1){System.err.println("ClassNotFoundException:"+e1.getMessage());}if(e.getSource()==but1){ //删除----------------------------try{String num1=t1.getText();String num2=t2.getText();String num3=t3.getText();sql2="delete from 学生成绩表where 学号='"+num1+"'and 课程名='"+num3+"'";con=DriverManager.getConnection(url,"root","123");stmt=con.createStatement();sql1="select * from 学生成绩表where 学号='"+num1+"' and 姓名='"+num2+"' and 课程名='"+num3+"'";ResultSet rs=stmt.executeQuery(sql1);if(rs.next()){stmt.executeUpdate(sql2);JOptionPane.showMessageDialog(this, "删除成功!");}else{JOptionPane.showMessageDialog(this, "没有此条记录!请重新输入");}t1.setText("");stmt.close();con.close();}catch(SQLException ex){System.err.println("SQLException:"+ex.getMessage());}}}}文件entry.java代码import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.*;class entry extends JFrame implements ActionListener{ int flag=1;String user,pass;JPanel pa;JLabel lab1,lab2;JTextField tf1;JPasswordField tf2;JButton btu1,btu2;JPanel pa1,pa2,pa4;entry(){super("学生成绩管理系统");setBounds(400,200,400,300);GridBagLayout gbL=new GridBagLayout();GridBagConstraints gbc=new GridBagConstraints();setLayout(gbL);gbc.fill=GridBagConstraints.HORIZONTAL;gbc.anchor=GridBagConstraints.CENTER;lab1=new JLabel("请输入帐号"); lab2=new JLabel("请输入密码");tf2=new JPasswordField(10);tf2.setEchoChar('*');tf1=new JTextField(10);tf1.addActionListener(this);pa1=new JPanel();pa1.add(lab1);pa1.add(tf1);gbc.gridx=1;gbc.gridy=1;gbc.insets=new Insets(2,5,0,5); gbL.setConstraints(pa1,gbc);add(pa1);tf2.addActionListener(this);pa2=new JPanel();pa2.add(lab2);pa2.add(tf2);gbc.gridx=1;gbc.gridy=2;gbc.insets=new Insets(2,5,2,5); gbL.setConstraints(pa2,gbc);add(pa2);btu1=new JButton("确定");btu1.addActionListener(this);btu2=new JButton("退出");btu2.addActionListener(this);pa4=new JPanel();pa4.add(btu1);pa4.add(btu2);gbc.gridx=1;gbc.gridy=4;gbc.insets=new Insets(2,5,2,5);gbL.setConstraints(pa4,gbc);add(pa4);}public void actionPerformed(ActionEvent e){ loginsure ls;if(e.getSource()==btu1){user=tf1.getText();pass=tf2.getText();try{ls=new loginsure(user,pass);this.setVisible(false);}catch (SQLException e1){e1.printStackTrace();}catch (ClassNotFoundException e1){e1.printStackTrace();}}if(e.getSource()==btu2){dispose();System.exit(0);}}}class loginsure{int i=0;String name=null,pwd=null, ustype=null;public loginsure(String s,String a) throws SQLException,ClassNotFoundException{ String driver ="org.gjt.mm.mysql.Driver";Class.forName(driver);String URL = "jdbc:mysql://localhost:3306/学生成绩系统";Connection conn = DriverManager.getConnection(URL,"root","123");Statement stmt=conn.createStatement();ResultSet rs = stmt.executeQuery("select * from 用户管理表");while (rs.next()){name=rs.getString("用户名").trim();pwd=rs.getString("密码").trim();ustype=rs.getString("权限组").trim();if (s.equals(name)&&a.equals(pwd)){i=1;if(ustype.trim().equals("管理员")){teacher tea=new teacher();tea.setVisible(true);}if(ustype.trim().equals("学生")){student stu=new student(name);stu.setVisible(true);}}}if(i==0)JOptionPane.showMessageDialog(null, "用户名或者密码错误", "警告",JOptionPane.WARNING_MESSAGE);stmt.close();conn.close();}}文件inquiry.java代码import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;class inquiry extends JFrame implements ActionListener{ JTextField t1;JTable table;JButton but1;JLabel lab1;JPanel p1;JTable table1=null;DefaultT ableModel demod1=null;String n[]={"课程名","状态","成绩"};String [][]data=new String[0][0];String No;inquiry(String no){super("成绩");No=no;setBounds(350,100,470,400);p1=new JPanel();lab1=new JLabel("课程名"); t1=new JTextField(10);but1=new JButton("查询成绩");but1.addActionListener(this);p1.add(lab1);p1.add(t1);p1.add(but1);demod1=new DefaultTableModel(data,n);table1=new JTable(demod1);JScrollPane s1=new JScrollPane(table1);p1.add(s1);add(p1);setVisible(true);}public void actionPerformed(ActionEvent e){int i=0;String sql1;String url="jdbc:mysql://localhost:3306/学生成绩系统";Connection con;Statement stmt;try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ng.ClassNotFoundException e1){System.err.println("ClassNotFoundException:"+e1.getMessage());}if(e.getSource()==but1){try{String num=t1.getText();sql1="select * from 学生成绩表where 学号='"+No+"'";if(!num.equals("")){sql1="select * from 学生成绩表where 课程名='"+num+"'and 学号='"+No+"'";}con=DriverManager.getConnection(url,"root","123");stmt=con.createStatement();ResultSet rs=stmt.executeQuery(sql1);removeAllRecord();while(rs.next()){Vector data=new Vector();data.addElement(rs.getString(3));data.addElement(rs.getString(4));data.addElement(rs.getString(5));demod1.addRow(data);i=1;}if(i==0){JOptionPane.showMessageDialog(this, "没有此课程!请重新输入");}table1.revalidate();t1.setText("");stmt.close();con.close();}catch(SQLException ex){System.err.println("SQLException:"+ex.getMessage());}}}public void removeAllRecord(){//将界面上的所有记录清空int rowcount;while(true){//删除所有存在的行rowcount = demod1.getRowCount()-1;if(rowcount >= 0){demod1.removeRow(rowcount);demod1.setRowCount(rowcount);}elsebreak;}}}import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;public class main{public static void main(String args[]){entry ent=new entry();ent.setVisible(true);ent.setResizable(false);}}import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;class record extends JFrame implements ActionListener{ JTextField t1;TextArea t;JButton but1;JLabel L1;JPanel p1;JTable table1=null;DefaultT ableModel demod1=null;String n[]={"平均成绩","优秀","良好","不及格"};String [][]data=new String[0][0];public record(){super("统计");setBounds(350,30,470,610);setLayout(new GridLayout(1,1,10,10));p1=new JPanel();L1=new JLabel("课程名");but1=new JButton("查询");but1.addActionListener(this);t1=new JTextField(10);p1.add(L1);p1.add(t1);p1.add(but1);demod1=new DefaultTableModel(data,n);table1=new JTable(demod1);JScrollPane s1=new JScrollPane(table1);p1.add(s1);add(p1);setVisible(true);}public void actionPerformed(ActionEvent e){int i=0;String sql1;String sql2;String url="jdbc:mysql://localhost:3306/学生成绩系统";Connection con;Statement stmt;try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ng.ClassNotFoundException e1){System.err.println("ClassNotFoundException:"+e1.getMessage());}if(e.getSource()==but1){try{String num1=t1.getText();if(num1.equals("")){JOptionPane.showMessageDialog(this, "学号不能为空","请输入学号!",JOptionPane.WARNING_MESSAGE);}else{sql1="select * from 学生成绩表where 学号='"+num1+"'";sql1="select avg(成绩) from 学生成绩表where 课程名='"+num1+"'";sql2="select count(*) from 学生成绩表where 课程名='"+num1+"' and 成绩>=90";con=DriverManager.getConnection(url,"root","123");stmt=con.createStatement();ResultSet rs=stmt.executeQuery(sql1);removeAllRecord();while(rs.next()){Vector data=new Vector();data.addElement(rs.getInt(1));/*data.addElement(rs.getString(3));data.addElement(rs.getString(4));data.addElement(rs.getString(5));*/demod1.addRow(data);i=1;}rs=stmt.executeQuery(sql2);while(rs.next()){int n = rs.getInt(1);System.out.println(n);}if(i==0){JOptionPane.showMessageDialog(this, "没有此条记录!请重新输入");}table1.revalidate();t1.setText("");stmt.close();con.close();}}catch(SQLException ex){System.err.println("SQLException:"+ex.getMessage());}}}public void removeAllRecord(){//将界面上的所有记录清空int rowcount;while(true){//删除所有存在的行rowcount = demod1.getRowCount()-1;if(rowcount >= 0){demod1.removeRow(rowcount);demod1.setRowCount(rowcount);}elsebreak;}}}文件revise.java代码import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;class revise extends JFrame implements ActionListener{ JTextField t1,t2,t3,t4,t5;JTable table;JButton but1;JLabel lab1,lab2,lab3,lab4,lab5;JPanel p1;int n=0;revise(){super("修改");setBounds(350,100,470,400);setLayout(new GridLayout(1,1,10,10));p1=new JPanel();lab1=new JLabel("学号"); t1=new JTextField(10);lab2=new JLabel("姓名"); t2=new JTextField(10);lab3=new JLabel("课程名"); t3=new JTextField(10);lab4=new JLabel("状态"); t4=new JTextField(10);lab5=new JLabel("成绩"); t5=new JTextField(10);but1=new JButton("修改");but1.addActionListener(this);p1.add(lab1);p1.add(t1);p1.add(lab2);p1.add(t2);p1.add(lab3);p1.add(t3);p1.add(lab4);p1.add(t4);p1.add(lab5);p1.add(t5);p1.add(but1);add(p1);setVisible(true);}public void actionPerformed(ActionEvent e){String sql1=null,update=null;String url="jdbc:mysql://localhost:3306/学生成绩系统";Connection con;Statement stmt;try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ng.ClassNotFoundException e1){System.err.println("ClassNotFoundException:"+e1.getMessage());}if(e.getSource()==but1){ //修改---------------------------try{String num1=t3.getText();String num2=t1.getText();//String num3=t5.getText();n= Integer.valueOf(t5.getText()).intValue();System.out.print(n);con=DriverManager.getConnection(url,"root","123");stmt=con.createStatement();sql1="select * from 学生成绩表where 学号='"+num2+"' and 课程名='"+num1+"'";update="update 学生成绩表set 课程名='"+t3.getText()+"',状态='"+t4.getText()+"',成绩='"+n+"' where 学号='"+num2+"'";ResultSet rs=stmt.executeQuery(sql1);if(rs.next()){stmt.executeUpdate(update);JOptionPane.showMessageDialog(this, "修改成功!");}else{JOptionPane.showMessageDialog(this, "没有此条记录!请重新输入");}t1.setText("");t2.setText("");t3.setText("");t4.setText("");t5.setText("");stmt.close();con.close();}catch(SQLException ex){System.err.println("SQLException:"+ex.getMessage());}}}}文件student.java代码import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;class student extends JFrame implements ActionListener{ inquiry cho;JMenuBar mb;JMenu m1;JMenuItem mt1,mt2;String No;Icon icon;JLabel lab;student(String no){super("学生");icon=new ImageIcon("123.jpg");lab=new JLabel(icon);add(lab);No=no;setBounds(130,10,800,500);JMenuBar mb=new JMenuBar();setJMenuBar(mb);m1=new JMenu("操作");mt1=new JMenuItem("查询成绩");mt2=new JMenuItem("退出");m1.add(mt1);mt1.addActionListener(this);m1.addSeparator();m1.add(mt2);mt2.addActionListener(this);m1.addActionListener(this);mb.add(m1);}public void actionPerformed(ActionEvent e){ if(e.getSource()==mt1)cho=new inquiry(No);if(e.getSource()==mt2)dispose();}}文件teacher.java代码import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;class teacher extends JFrame implements ActionListener{ addmessage add;deletemessage delete;revise re;user use;record rec;MenuBar mb;Menu m1;MenuItem mt1,mt2,mt3,mt4,mt5,mt6;Icon icon;JLabel lab;teacher(){super("管理员");setBounds(130,10,800,500);MenuBar mb=new MenuBar();setMenuBar(mb);m1=new Menu("操作");mt1=new MenuItem("增加"); mt2=new MenuItem("删除"); mt3=new MenuItem("修改"); mt4=new MenuItem("查询"); mt5=new MenuItem("统计"); mt6 = new MenuItem("退出"); icon=new ImageIcon("123.jpg"); lab=new JLabel(icon);add(lab);mt1.addActionListener(this);m1.add(mt1);mt2.addActionListener(this);m1.add(mt2);mt3.addActionListener(this);m1.add(mt3);mt4.addActionListener(this);m1.add(mt4);mt5.addActionListener(this);m1.add(mt5);m1.addSeparator();mt6.addActionListener(this);m1.add(mt6);m1.addActionListener(this);mb.add(m1);}public void actionPerformed(ActionEvent e){if(e.getSource()==mt1)add=new addmessage();if(e.getSource()==mt2)delete=new deletemessage();if(e.getSource()==mt3)re=new revise();if(e.getSource()==mt4)use=new user();if(e.getSource()==mt5)rec=new record();if(e.getSource()==mt6)dispose();}}文件user.java代码import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;class user extends JFrame implements ActionListener{ JTextField t1,t2;TextArea t;JButton but1;JLabel L1,L2;JPanel p1;JTable table1=null;DefaultT ableModel demod1=null;String n[]={"姓名","课程名","状态","成绩"};String [][]data=new String[0][0];public user(){super("查询");setBounds(350,30,470,610);setLayout(new GridLayout(1,1,10,10));p1=new JPanel();L1=new JLabel("学号");L2=new JLabel("课程名");but1=new JButton("查询");but1.addActionListener(this);t1=new JTextField(10);t2=new JTextField(10);p1.add(L1);p1.add(t1);p1.add(L2);p1.add(t2);p1.add(but1);demod1=new DefaultTableModel(data,n);table1=new JTable(demod1);JScrollPane s1=new JScrollPane(table1);p1.add(s1);add(p1);setVisible(true);}public void actionPerformed(ActionEvent e){ int i=0;String sql1;String url="jdbc:mysql://localhost:3306/学生成绩系统";Connection con;Statement stmt;try{Class.forName("org.gjt.mm.mysql.Driver");}catch(ng.ClassNotFoundException e1){System.err.println("ClassNotFoundException:"+e1.getMessage());}if(e.getSource()==but1){try{String num1=t1.getText();String num2=t2.getText();if(num1.equals("")){JOptionPane.showMessageDialog(this, "学号不能为空","请输入学号!",JOptionPane.WARNING_MESSAGE);}else{sql1="select * from 学生成绩表where 学号='"+num1+"'";if(!num2.equals("")){sql1="select * from 学生成绩表where 课程名='"+num2+"'and 学号='"+num1+"'";}con=DriverManager.getConnection(url,"root","123");stmt=con.createStatement();ResultSet rs=stmt.executeQuery(sql1);removeAllRecord();while(rs.next()){Vector data=new Vector();data.addElement(rs.getString(2));data.addElement(rs.getString(3));data.addElement(rs.getString(4));data.addElement(rs.getString(5));demod1.addRow(data);i=1;}if(i==0){JOptionPane.showMessageDialog(this, "没有此条记录!请重新输入");}table1.revalidate();t1.setText("");stmt.close();con.close();}}catch(SQLException ex){System.err.println("SQLException:"+ex.getMessage());}}}public void removeAllRecord(){//将界面上的所有记录清空int rowcount;while(true){//删除所有存在的行rowcount = demod1.getRowCount()-1;if(rowcount >= 0){demod1.removeRow(rowcount);demod1.setRowCount(rowcount);}elsebreak;}}}附件sql语句create table 用户管理表(用户名varchar(25),密码varchar(15),权限组varchar(15))insert into 用户管理表values('01','01','学生')insert into 用户管理表values('admin','admin','管理员') select * from 用户管理表create table 学生成绩表(学号varchar(25),姓名varchar(15),课程名varchar(25),状态varchar(5),成绩int(11))insert into 学生成绩表values('01','朱亮','数据库','通过','88') insert into 学生成绩表values('02','张三','数据库','未通过','55') select * from 学生信息管理表。

java阶段项目:学生成绩管理系统(面向对象)

java阶段项目:学生成绩管理系统(面向对象)

Java 学生信息管理系统(面向对象)一:效果如下:二:具体实现代码如下:Student类Student .javapublic class Student {private int id;private String name;private int age;private int java;private int csharp;private int html;private int sql;private int sum;private int avg;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) { = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public int getJava() {return java;}public void setJava(int java) { this.java = java;}public int getCsharp() {return csharp;}public void setCsharp(int csharp) { this.csharp = csharp;}public int getHtml() {return html;}public void setHtml(int html) { this.html = html;}public int getSql() {return sql;}public void setSql(int sql) {this.sql = sql;}public int getSum() {return sum;}public void setSum() {this.sum = this.java+this.csharp+this.html+this.sql;}public int getAvg() {return avg;}public void setAvg() {this.avg = this.sum/4;}public String toString(){Stringmsg="\t"+this.id+"\t"++"\t"+this.age+"\t"+this.java+"\t"+this.csharp+"\t"+this.html+"\t"+this.sql+"\t"+this.sum+"\t" +this.avg;return msg;}}学生信息管理类StudentAdmin.javaimport java.util.Scanner;public class StudentAdmin {String msg="\t编号\t姓名\t年龄\tjava\tcsharp\thtml\tsql\t总分\t平均分";//打印现有学生public void print(Student [] stu){System.out.println(msg);for(int i=0;i<stu.length;i++){if(stu[i]!=null){System.out.println(stu[i]);}}}//添加学生public void addStudent(String name,int age,Student [] stu) {Student student=new Student();student.setName(name);student.setAge(age);int i=this.getIndex(stu);if(i==9999){System.out.println("数组已经容纳最大量,不能再接受");}else{student.setId(i);}stu[i]=student;}//获取编号public int getIndex(Student [] stu){for(int i=0;i<stu.length;i++){if(stu[i]==null){return i;}}return 9999;}//根据学生编号查找学生public void selectStudent(int id,Student [] stu){System.out.println(msg);for(int i=0;i<stu.length;i++){if(stu[i]!=null){if(this.exits(id, stu[i])){if(stu[i].getId()==id){System.out.println(stu[i]);return;}}}}System.out.println("\t没有这个学生存在!!!");}//查询学生是否存在public boolean exits(int id,Student stu){if(stu!=null){if(stu.getId()==id){return true;}else{return false;}}return false;}//更新学生信息public void updateStudent(int id,String name,int age,Student [] stu) {for(int i=0;i<stu.length;i++){if(stu[i]!=null){if(this.exits(id, stu[i])){if(stu[i].getId()==id){stu[i].setName(name);stu[i].setAge(age);System.out.println("--更新学生信息成功--");return;}}}}System.out.println("该学生不存在!!!");}public void deleteStudent(int id,Student [] stu){for(int i=0;i<stu.length;i++){if(this.exits(id, stu[i])){stu[i]=null;this.print(stu);System.out.println("\t--删除学生成功--");return;}}System.out.println("删除学生失败");}//根据学生编号获取学生姓名public String getName(int id,Student [] stu){for(int i=0;i<stu.length;i++){if(this.exits(id, stu[i])){return stu[i].getName();}}return null;}//根据学生编号输入学生成绩public void inputScore(int id,Student [] stu,Scanner input) {String name=this.getName(id, stu);System.out.println("请输入"+name+"的java成绩:");int java=input.nextInt();System.out.println("请输入"+name+"的csharp的成绩:");int csharp=input.nextInt();System.out.println("请输入"+name+"的html的成绩:");int html=input.nextInt();System.out.println("请输入"+name+"的sql的成绩:");int sql=input.nextInt();for(int i=0;i<stu.length;i++){if(this.exits(id, stu[i])){stu[i].setJava(java);stu[i].setCsharp(csharp);stu[i].setHtml(html);stu[i].setSql(sql);stu[i].setSum();stu[i].setAvg();break;}}this.print(stu);}//指定某门课的成绩排序public void scoreSort(int num,Student [] stu){Student [] arr=stu;if(num==1){for(int i=0;i<stu.length-1;i++){for(int j=i+1;j<stu.length;j++){if(stu[i]!=null&&stu[j]!=null){if(stu[i].getJava()<stu[j].getJava()){Student s=arr[i];arr[i]=arr[j];arr[j]=s;}}}}this.print(arr);}else if(num==2){for(int i=0;i<stu.length-1;i++){for(int j=i+1;j<stu.length;j++){if(stu[i]!=null&&stu[j]!=null){if(stu[i].getCsharp()<stu[j].getCsharp()){Student s=arr[i];arr[i]=arr[j];arr[j]=s;}}}}this.print(arr);}else if(num==3){for(int i=0;i<stu.length-1;i++){for(int j=i+1;j<stu.length;j++){if(stu[i]!=null&&stu[j]!=null){if(stu[i].getHtml()<stu[j].getHtml()){Student s=arr[i];arr[i]=arr[j];arr[j]=s;}}}}this.print(arr);}else if(num==4){for(int i=0;i<stu.length-1;i++){for(int j=i+1;j<stu.length;j++){if(stu[i]!=null&&stu[j]!=null){if(stu[i].getSql()<stu[j].getSql()){Student s=arr[i];arr[i]=arr[j];arr[j]=s;}}}}this.print(arr);}}//总分排序public void sumSort(Student [] stu){Student [] arr=stu;for(int i=0;i<arr.length-1;i++){for(int j=i+1;j<arr.length;j++){if(arr[i]!=null&&arr[j]!=null){if(arr[i].getSum()<arr[j].getSum()){Student s=arr[j];arr[j]=arr[i];arr[i]=s;}}}}this.print(arr);}}测试类Test.Javaimport java.util.Scanner;public class Test {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner input=new Scanner(System.in);StudentAdmin admin=new StudentAdmin();System.out.println("请输入学生的人数:");int studentNumber=input.nextInt();Student [] students=new Student[studentNumber];while(true){System.out.println("请选择要执行的功能(输入编号):");System.out.println("10:添加一个学生");System.out.println("11:查找一个学生");System.out.println("12:根据学生编号更新学生基本信息");System.out.println("13:根据学生编号删除学生");System.out.println("14:根据编号输入学生各门科的成绩");System.out.println("15:根据某门成绩进行排序");System.out.println("16:根据总分进行排序");System.out.println("99:退出系统");int number=input.nextInt();if(number==10){System.out.println("--执行添加学生操作--");System.out.println("请输入要添加学生的姓名:");String name=input.next();System.out.println("请输入要添加学生的年龄:");int age=input.nextInt();admin.addStudent(name, age, students);admin.print(students);}else if(number==11){System.out.println("--执行查找学生操作--");System.out.println("请输入要查找学生的编号:");admin.selectStudent(input.nextInt(), students);}else if(number==12){System.out.println("执行更新学生信息操作");System.out.println("请输入要修改信息学生的编号");int id=input.nextInt();System.out.println("请输入修改后学生的姓名:");String name=input.next();System.out.println("请输入修改后学生的年龄:");int age=input.nextInt();admin.updateStudent(id, name, age, students);admin.print(students);}else if(number==13){System.out.println("--执行删除操作--");System.out.println("请输入要删除学生的编号:");int id=input.nextInt();admin.deleteStudent(id, students);}else if(number==14){System.out.println("--执行输入学生成绩操作--");System.out.println("请输入要输入成绩学生的编号:");int id=input.nextInt();admin.inputScore(id, students, input);}else if(number==15){System.out.println("执行成绩排序操作");System.out.println("请选择用什么成绩排序:(1:java 2:charp 3:html 4:sql)");int score=input.nextInt();admin.scoreSort(score, students);}else if(number==16){System.out.println("执行总分排序操作");admin.sumSort(students);}else if(number==99){System.out.println("退出系统成功!!!");break;//System.exit(0);}else{System.out.println("输入有误,请重新输入");}}}}。

【系统】Java学生成绩管理系统源代码

【系统】Java学生成绩管理系统源代码

【关键字】系统Java学生成绩管理系统源代码Java学生成绩管理系统源代码import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;/** Created on*//*** @author 让炜* @since 1.0** TODO 学生成绩管理系统* 通过学号查找,修改,删除数据**/public class LittleProgram{static boolean isDelete = true;static boolean isFind = true;public static void main(String [] args)//主方法,程序从这里开始运行throws IOException,NumberNotFoundException{int choice=-1;do{LittleProgram lp = new LittleProgram();;"\t####################################"); ;"\t\t Java学生成绩管理系统1.1");"\t\t请用学号查找,修改,删除数据");;"\t####################################\n"); "1.增加数据:\n"+"2.查找数据:\n"+"3.删除数据:\n"+"4.清除所有数据:\n"+"5.把数据全部打印到屏幕\n"+"6.把成绩按学号排序\n"+"7.修改数据\n"+"8.统计已记录成绩学生数\n"+"9.关于作者\n"+"0.退出程序.\n" +"输入:");BufferedReader in = //从终new BufferedReader( //端接new InputStreamReader(System.in));//收数String inputLine = in.readLine(); //字选choice= Integer.valueOf(inputLine).intValue();//项; switch(choice){case 1: {//1.增加数据String str = lp.inputData();lp.addData(str);"增加数据成功.");timeOut(1);}break;case 2: {//2.查找数据long find = 0;"请输入你要查找的学生学号:"); BufferedReader inn =new BufferedReader(new InputStreamReader(System.in));String inputLi = inn.readLine();find = Integer.valueOf(inputLi).longValue();lp.findData(find);timeOut(2);}break;case 3: {//3.删除数据long deleteNumber = 0;"请输入你想删除的同学的学号:"); BufferedReader bf =new BufferedReader (new InputStreamReader(System.in));String inputL = bf.readLine();deleteNumber = Integer.valueOf(inputL).longValue(); lp.deleteData(deleteNumber);if(isDelete)"删除数据成功!");timeOut(1);}break;case 4: {lp.clearData();//4.清除所有数据timeOut(1);}break;case 5: {print();//5.把数据全部打印到屏幕timeOut(2);}break;case 6: {lp.numSort();//6.把成绩按学号排序"按照学号从小到大排序成功!\n"+"排序后:\n");print();timeOut(2);}break;case 7: {lp.rewrite();//7.修改数据timeOut(2);}break;case 8: {int count = lp.count();"共有"+count+"个学生已经记录.");timeOut(2);}break;case 9: {"\t\t让炜\n"+"\t\t上海电力学院通信工程系\n"+"\t\tQQ:0\n");timeOut(4);}break;}while (choice != 0);"Bye! ^-^");System.exit(0);}public String inputData()//从终端接收数据的方法,返回字符串throws IOException,NumberFormatException{"请依次输入:学号姓名性别成绩\n" +"每项数据请用空格隔开:");String all = "";try{BufferedReader in = //从终new BufferedReader ( //端接new InputStreamReader(System.in)); //收数String inputLine = in.readLine(); //据StringTokenizer str =new StringTokenizer(inputLine," ");//接收的数据用空格隔开,这个类用来提取每个字符串long num = Integer.valueOf(str.nextToken()).longValue();//学号String name = (String)str.nextToken(); //姓名String sex = (String)str.nextToken(); //性别double mark = Integer.valueOf(str.nextToken()).doubleValue();//分数all = String.valueOf(num) +" , "+name +" , "+sex +" , "+String.valueOf(mark);//把所有的数据用" , "隔开然后在连起来放进字符串all}catch (IOException e){}catch (NumberFormatException e){}return all;//返回字符串all}public void addData(String str)//增加数据的方法throws IOException{String s1 ="",s2="" ,s3= "";File file = new File("data.txt");if (file.exists())//如果文件data.txt存在{try{BufferedReader in =new BufferedReader(new FileReader("data.txt"));while ((s1=in.readLine())!=null)s2+=s1+"\n";//把文件中的每行数据全部放进一个字符串s2s2+=str+"\n"; //再把s2于形参str相连放进s2BufferedReader in2 = //把字符new BufferedReader( //串s2也new StringReader(s2)); //就是原PrintWriter out = //文件+new PrintWriter( //形参str(新输入的一行数据)new BufferedWriter( //重新写进data.txtnew FileWriter("data.txt"))); //覆盖原来的数据while ((s3=in2.readLine())!= null){out.println(s3);}out.close();//"write data true.");}catch (IOException e){}}else{"File \"data\" Missing!");}}public void clearData()//清除data.txt的所有数据的方法throws IOException{File file = new File("data.txt");if(file.exists())//如果文件在{try{PrintWriter out =new PrintWriter(new BufferedWriter(new FileWriter(file)));out.print("");//在文件data.txt里写进一个空字符,所以清除了原来的内容out.close(); //关闭文件"clear data true!");}catch(IOException e){}}else{"File \"data\" Missing!");}}public void deleteData(long deleteNumber)//删除某条数据throws IOException,FileNotFoundException{isDelete = true;try{DataMap mp = new DataMap();//生成一个自己编写的容器long j=0;String s1="",s2="",s3="";BufferedReader in =new BufferedReader(new FileReader("data.txt"));while ((s1=in.readLine())!=null){j=numberTokenizer(s1);mp.put(j,s1);}try{if(mp.containsKey( String.valueOf(deleteNumber).toString())) {mp.remove(deleteNumber);}elsethrow new NumberNotFoundException();Collection c = mp.values();Iterator iter = c.iterator();while(iter.hasNext()){s1 = (String)iter.next();s3 +=s1+"\n";}BufferedReader in2 =new BufferedReader(new StringReader(s3));PrintWriter out =new PrintWriter(new BufferedWriter(new FileWriter("data.txt")));//"delete No"+deleteNumber);while( (s1 = in2.readLine())!=null){out.println(s1);}out.close();}catch (NumberNotFoundException e){isDelete = false;" no found :(");}}catch(IOException e){}}public long numberTokenizer(String s)throws IOException{StringTokenizer st =new StringTokenizer(s," ");return Integer.valueOf((st.nextToken())).longValue();}public void findData(long find)//查找数据throws IOException,NumberNotFoundException{isFind = true;String s = "",findString ="";long i;DataMap dm = new DataMap();BufferedReader in =new BufferedReader(new FileReader("data.txt"));while ((s=in.readLine())!=null){i=numberTokenizer(s);dm.put(i,s);}//in.close();try{if(dm.containsKey( String.valueOf(find).toString())){findString = dm.get(find);"学号"+find+"学生的资料是:");;}elsethrow new NumberNotFoundException();}catch (NumberNotFoundException e){" no found :(");isFind = false;}}public static void print()//读取文本文件把数据打印到终端的方法throws IOException{try{BufferedReader in =new BufferedReader(new FileReader("data.txt"));String read = "";while ((read = in.readLine())!=null);}catch(IOException e){}}public static void timeOut(double sec)//停顿短暂时间的一个方法完全可以不要这个功能{double seconds = sec;long t = System.currentTimeMillis()+(int)(seconds*1000); while ((System.currentTimeMillis())<t);}public void numSort()//按学号排序throws IOException{long i = 0;String s = "";try{DataArrayList dal = new DataArrayList(); BufferedReader in =new BufferedReader(new FileReader("data.txt"));while ((s=in.readLine())!=null){i=numberTokenizer(s);dal.add(i);}Collections.sort(dal);DataMap dm = new DataMap();BufferedReader in2 =new BufferedReader(new FileReader("data.txt"));while ((s=in2.readLine())!=null){i=numberTokenizer(s);dm.put(i,s);}PrintWriter out =new PrintWriter (new BufferedWriter(new FileWriter("data.txt")));Iterator it = dal.iterator();long temp = 0;String tempStr = "";while (it.hasNext()){temp = Integer.valueOf((String)it.next()).longValue(); tempStr = dm.get(temp);out.println(tempStr);}out.close();}catch(IOException e){}}public void rewrite()throws IOException,NumberNotFoundException {try{"请输入你要修改的学生学号:"); BufferedReader in =new BufferedReader (new InputStreamReader(System.in));String inputLine = in.readLine();long num = Integer.valueOf(inputLine).longValue(); findData(num);if(isFind){deleteData(num);"请重新输入该学生的资料:");String str = inputData();addData(str);"rewrite true!");}}catch(IOException e){}catch(NumberNotFoundException e){}}public int count()throws IOException{DataArrayList dal = new DataArrayList();try{String s = "";long i =0;BufferedReader in =new BufferedReader(new FileReader("data.txt"));while ((s=in.readLine())!=null){i=numberTokenizer(s);dal.add(i);}}catch(IOException e){}return dal.size();}}/*** @author RangWei* TODO 这是个我们写的一个容器,继承公共类HashMap* 大概的功能就相当一个数组**/class DataMap extends HashMap//一个保存数据的Map{public void put(long i,String str)//把学号和数据放进这个Map{ //以后一个学号(key)对应的是一个人的数据(value)put(String.valueOf(i).toString(),str);}public void remove(long i)//接收学号,然后删除学号(key)和它对应的数据(value) {remove(String.valueOf(i).toString().toString());}public String get(long i)//接收一个学号,然后返回这个key对应的value{String s = String.valueOf(i).toString();if (!containsKey(s)){"Not found Key: "+s);}return (String)get(s);}}/*** @author RangWei** TODO 这个类继承ArrayList* 用来按数字排序,在用学号排序时要用到它**/class DataArrayList extends ArrayList{public void add(long num){String numToString = String.valueOf(num).toString();add(numToString);}}/*文档来源为:从网络收集整理.word版本可编辑.欢迎下载支持.** @author RangWei** TODO 增加的一个Exception,主要是在文件里没有要找* 的学号就抛出**/class NumberNotFoundException extends Exception{public NumberNotFoundException(){}}此文档是由网络收集并进行重新排版整理.word可编辑版本!11。

一个简单的学生成绩管理信息系统(Java)

一个简单的学生成绩管理信息系统(Java)

一个简单的学生成绩管理信息系统(Java)一个简单的学生成绩管理信息系统题目:数据库要求:1.建立的数据库中包含如下信息:学生学号、姓名、班级,语文、数学、英语成绩。

2.至少要有5个班级,每个班级要有10名以上学生。

3.使用.txt格式文本表示各种表。

功能需求:1.能够实现根据以下关键字查询:学生姓名、学号、班级、课程名称。

2.能够实现按照单科成绩、总成绩、平均成绩、学号排序。

3.能够实现学生信息的插入、删除和修改。

4.能够查询每个课程的最高分、最低分及相应学生姓名、班级和学号。

5.能够查询每个班级某门课程的优秀率(90分及以上)、不及格率,并进行排序。

界面要求:使用图形界面实现,要符合日常软件使用规范来设计菜单和界面。

需求分析:界面:要符合日常软件使用规范,使用方便,外形简洁美观。

功能需求:存储学生学号、姓名、班级,语文、数学、英语成绩等信息,实现数据库的读取与存入,数据项的记录与修改,删除等。

设计思想:类设计:将添加数据、查询数据、删除数据、修改数据四个功能分别为四个类来实现,为了便于测试,每一个类都继承了主窗口类JFRAME,使得窗口可以独自运行。

INSERT类设计:功能组件6个文本域、6个标签、1个按钮。

功能实现添加数据。

实现过程对按钮添加监控,实现按钮事件为获取文本域中的信息,并执行SQL的INSERT语句。

QUERY类设计:功能组件5个按钮、三个单行文本组件、1个下拉框、1个多行文本。

功能实现按学号查询、按姓名查询、按班级查询、按课程查询、显示全部。

实现过程对按钮添加监控,共有五个监控事件,前三个实现按钮事件为先获取文本域中的信息,根据对应查询的要求执行相应的SQL的SELLECT语句;按课程查询通过在下拉框中选择对应的选项,即查询相应的课程;第五个查询按钮将全部信息在多行文本框中输出。

MODIFY类设计:功能组件6个单行文本、6个标签、1个按钮。

功能实现修改数据。

实现过程与添加数据类似,对按钮添加监控,实现按钮事件为获取文本域中的信息,并执行SQL的UPDATE语句;不同的是以学号为主键进行查找并更新。

java学生成绩管理系统代码

java学生成绩管理系统代码

JAVA学生成绩管理系统代码import javax.swing。

*;import java.awt.*;import java.awt.event。

*;import java。

sql.*;import javax.swing。

*;import java.awt.*;import java.awt.event.*; import java。

awt。

event.*;import javax.swing.*;import java。

awt。

*;import java。

awt。

event.*;import java.sql。

*;import javax.swing。

table.JTableHeader; import javax。

swing。

*;import java.awt.*;import java。

awt.event。

*;import java.sql。

*;import javax.swing.*;import java。

awt。

*;import java。

awt.event。

*;import java.sql。

*;import javax.swing.*;import java。

awt。

*;import java。

awt.event。

*;import java。

sql.*;import javax。

swing.*;import java。

awt。

*;import java。

awt。

event。

*;import java.sql.*;import javax.swing。

table.DefaultTableModel; import javax。

swing.table。

JTableHeader; import javax.swing.*;import java。

awt。

*;import java.awt。

event。

*;import java。

sql.*;class AddForm extends JFrame implements ActionListener{JLabel labName=new JLabel("学号:”);JLabel labDate=new JLabel("出生日期:");JLabel labScore=new JLabel(”成绩:”);JTextField txtName=new JTextField(20);JTextField txtDate=new JTextField(18);JTextField txtScore=new JTextField(20);JButton btnOk=new JButton(”确定”);JButton btnClear=new JButton(”清空");JPanel pan=new JPanel();JPanel pan1=new JPanel();JPanel pan2=new JPanel();JPanel pan3=new JPanel();JPanel pan4=new JPanel();Connection cnn;Statement stm;ResultSet rs;AddForm(){super("添加数据”);setSize(400,300);setDefaultCloseOperation(JFrame。

基于JAVA的学生成绩管理系统源代码

基于JAVA的学生成绩管理系统源代码

Java程序设计系电气信息系专业软件班级1342学号131842352姓名朱家军题目学生成绩管理系统任课教师一:要求1、用到书上(课本或实验册)上的至少三个实例2、用到至少两种布局和至少四种组件3、用到对话框4、用到对数据库的查询、删除、添加和修改5、最好用到输入输出流6、具有一定的实际意义二:内容本系统用access作为数据库,用到了书上的布局实例和数据库连接实例功能: 1、输入十个同学的学号,姓名,出生日期,二科成绩(学,大学英语) 。

2、输入学号查询学生信息。

3、删除记录4、查询记录5、添加记录6、修改记录1.简单的方式(java)import java.awt.Button;import java.awt.Color;import java.awt.FlowLayout;import java.awt.Font;import java.awt.Frame;import bel;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.JOptionPane;public class 查询成绩登陆系统extends Frame{ private Label lab_stuNum,lab_stuPassword;private TextField tf_stuNum,tf_stuPassword; private Button bt_login,bt_reset;public Label getLab_stuNum() {if(b_stuNum==null){b_stuNum=new Label("学号");}return lab_stuNum;}public Label getLab_stuPassword() {if(b_stuPassword==null){b_stuPassword=new Label("密码");}return lab_stuPassword;}public TextField getTf_stuNum() {if(this.tf_stuNum==null){this.tf_stuNum=new TextField(15);}return tf_stuNum;}public TextField getTf_stuPassword() {if(this.tf_stuPassword==null){this.tf_stuPassword=new TextField(15);this.tf_stuPassword.setEchoChar('●');}return tf_stuPassword;}public Button getBt_login() {if(this.bt_login==null){this.bt_login=new Button("登陆");this.bt_login.addActionListener(new ActionListener(){@Overridepublic void actionPerformed(ActionEvent e) {String account=tf_stuNum.getText();if(account==null||"".equals(account)){JOptionPane.showMessageDialog(查询成绩登陆系统.this, "请输入学号");tf_stuNum.requestFocus();}String pw=tf_stuPassword.getText();if(pw==null||"".equals(pw)){JOptionPane.showMessageDialog(查询成绩登陆系统.this, "请输入密码");tf_stuPassword.requestFocus();}String db_account="admin";String db_password="000000";if(account.equals(db_account)&&pw.equals(db_password)){JOptionPane.showMessageDialog(查询成绩登陆系统.this, "登陆成功");查询成绩登陆系统.this.dispose();}else{JOptionPane.showMessageDialog(查询成绩登陆系统.this,"账号密码不对");tf_stuNum.setText("");tf_stuPassword.setText("");tf_stuNum.requestFocus();}}2.C语言#include <stdio.h>#include <string.h>#include <stdlib.h>#include <windows.h>struct student //结构体定义{int num;char name[10];char birthday[10];int Cyuyan;int shujujiegou;struct student *next;};struct student *creat_by_input();struct student *get_last_student(struct student *head);struct student *Print_menu_main() //主菜单{printf("*********************************************************************\n");printf(" | 1.........输入学生信息| \n");printf(" | 2.........输出学生信息| \n");printf(" | 3.........查找学生信息| \n");printf(" | 4.........修改学生信息| \n");printf(" | 5.........插入学生信息| \n");printf(" | 6.........删除学生信息| \n");printf(" | 7.........排序学生信息| \n");printf(" | 0.........退出系统| \n");printf(" |_ _ _ _ _ _ _ _ _ _ _ _ _ | \n");}struct student *print_table_head(){printf("+----------+----------+----------+----------+-------------+\n");printf("| 学号| 姓名| 出生日期| c成绩|数据结构成绩|\n");printf("+----------+----------+----------+----------+-------------+\n");}struct student *print_table_row(struct student *p){printf("|%10d|%10s|%10s|%10d|%10d|\n",p->num,p->name,p->birthday,p->Cyuyan,p->shuju jiegou);}void print_table_bottom(){printf("+----------+----------+----------+----------+-------------+\n");}struct student * Creat_stu_record() //建立链表{struct student *plaststu=NULL,*pnewstu;char continue_input='N';struct student *head=NULL;while(1){if(head==NULL){head=creat_by_input();print_table_head();print_table_row(head);print_table_bottom();}else{pnewstu=creat_by_input();print_table_head();print_table_row(pnewstu);print_table_bottom();plaststu=get_last_student(head);plaststu->next=pnewstu;}printf("是否继续输入学生信息?(Y 继续,N 返回菜单)\n");getchar();continue_input=getchar();if(continue_input=='n'||continue_input=='N'){system("cls");Print_menu_main();break;}}return head;}struct student *creat_by_input(){struct student *pnewstu=(struct student *)malloc(sizeof(struct student));printf("请输入学生信息\n");printf("学号:");scanf("%d",&pnewstu->num);printf("姓名:");scanf("%s",pnewstu->name);printf("出生年月:");scanf("%s",pnewstu->birthday);printf("请输入学生成绩\n");printf("C语言:");scanf("%d",&(pnewstu->Cyuyan));printf("数据结构:");scanf("%d",&(pnewstu->shujujiegou));pnewstu->next=NULL;return pnewstu;}struct student *get_last_student(struct student *p ){if(p->next==NULL)return p;elsereturn get_last_student(p->next);}void Print_Stu_Doc(struct student *head){struct student *p;char r;print_table_head();if(head==NULL){printf("\n No Records\n");}for(p=head;p;p=p->next){printf("|%10d|%10s|%10s|%10d|%10d|\n",p->num,p->name,p->birthday,p->Cyuyan,p->shuju jiegou);printf("+----------+----------+----------+----------+-------------+\n");}printf("(按Enter键返回主菜单)\n");getchar();r=getchar();if(r!='1'){system("cls");Print_menu_main();}else{system("cls");Print_menu_main();}}struct student *search_by_name(struct student *head)//按姓名查找{char name[10];struct student *p=head;char continue_input;/*int isfound=0;*/printf("请输入要查找的姓名:");scanf("%s",name);printf("查找%s\n",name);print_table_head();while(p!=NULL){if(strcmp(p->name,name)==0){print_table_row(p);p=p->next;/* isfound=1; */break;}p=p->next;}print_table_bottom();printf("是否继续查找?(Y 继续;N 返回主菜单)\n");getchar();continue_input=getchar();if(continue_input=='n'||continue_input=='N'){system("cls");Print_menu_main();}elsesearch_by_name(head);}struct student * search_by_id(struct student *head)//按学号查找{int id;struct student *p=head;char continue_input;/*int isfound=0;*/printf("请输入要查找的学号:");scanf("%d",&id);printf("查找%d\n",id);print_table_head();while(p!=NULL){if(p->num==id){print_table_row(p);p=p->next;/*isfound=1;*/break;}p=p->next;}print_table_bottom();printf("是否继续查找?(Y 继续;N 返回主菜单)\n");getchar();continue_input=getchar();if(continue_input=='n'||continue_input=='N'){system("cls");Print_menu_main();}elsesearch_by_id(head);return head;}struct student*modify_record_by_id(struct student*head)//按学号修改{struct student *p=head;int id;char continue_input;printf("请输入要修改的学生的学号:\n");scanf("%d",&id);while(p!=NULL){if(p->num==id)break;p=p->next;}if(p==NULL)printf("抱歉,没有学号为%d的学生\n",id);else{printf("请输入学生信息:\n");printf("学号:");scanf("%d",&(p->num));printf("姓名:");scanf("%s",&(p->name));printf("出生年月:");scanf("%s",&(p->birthday));printf("请输入学生成绩:\n");printf("C语言:");scanf("%d",&(p->Cyuyan));printf("数据结构:");scanf("%d",&(p->shujujiegou));print_table_head();print_table_row(p);print_table_bottom();}printf("继续修改学生信息吗?Y 继续;N 返回主菜单\n");getchar();continue_input=getchar();if(continue_input=='y'||continue_input=='Y')creat_by_input();else{system("cls");Print_menu_main();}return head;}struct student*modify_record_by_name(struct student*head)//按姓名修改{struct student*p=head;char name[10];char continue_input;printf("请输入要修改的学生的姓名:\n");scanf("%s",name);while(p!=NULL){if(strcmp(p->name,name)==0)break;p=p->next;}if(p==NULL)printf("抱歉,没有姓名为%s的学生\n",name);else{printf("请输入学生信息:\n");printf("学号:");scanf("%d",&(p->num));printf("姓名:");scanf("%s",&(p->name));printf("出生年月:");scanf("%s",&(p->birthday));printf("请输入学生成绩:\n");printf("C语言:");scanf("%d",&(p->Cyuyan));printf("数据结构:");scanf("%d",&(p->shujujiegou));print_table_head();print_table_row(p);print_table_bottom();}printf("继续修改学生信息吗?Y 继续;N 返回主菜单\n");getchar();continue_input=getchar();if(continue_input=='y'||continue_input=='Y')creat_by_input();else{system("cls");Print_menu_main();}return head;}struct student *insert_record(struct student *head)//插入{struct student *ptr1;struct student *ptr,*stud;struct student *ptr2=head;char continue_input='N';int id;printf("请输入一个学号,在此之前插入学生信息:");scanf("%d",&id);stud=creat_by_input();ptr=stud;if(head==NULL){head=ptr;head->next=NULL;}else if(head->num==id){ptr->next=head;head=ptr;}else{while(ptr2!=NULL){ptr1=ptr2;ptr2=ptr1->next;if(ptr2->num==id){ptr1->next=ptr;ptr->next=ptr2;break;}}}print_table_head();print_table_row(ptr);print_table_bottom();printf("是否继续插入学生信息?(Y 继续N 返回主菜单)\n");getchar();continue_input=getchar();if(continue_input=='y'||continue_input=='Y')return insert_record(head);else{system("cls");Print_menu_main();return head;}}struct student *Delete_record_by_id( struct student *head)//按学号删除{struct student *p=head,*ppre=NULL;int id;char continue_input;printf("请输入要删除的学号:");scanf("%d",&id);while(p!=NULL){if(p->num==id)break;p=p->next;}if(p==NULL)printf("抱歉,没有该学号的学生信息!\n");else{printf("确定要删除学号为%d的学生的信息吗?(Y 确定;N 返回主菜单)\n",p->num);getchar();continue_input=getchar();if(continue_input=='y'||continue_input=='Y'){ppre=head;if(ppre==p){head=p->next;printf(" \n");free(p);}else{while(ppre!=NULL){if(ppre->next==p){ppre->next=p->next;free(p);break;}ppre=ppre->next;}}printf("删除成功!");}// Print_menu_main();}printf("继续删除学生信息吗?(Y 继续;N 返回主菜单)");getchar();continue_input=getchar();if(continue_input=='y'||continue_input=='Y')Delete_record_by_id(head);else{system("cls");Print_menu_main();return head;}return 0;}struct student *Delete_record_by_name( struct student *head)// 按姓名删除{struct student *p=head,*ppre=NULL;char name[10];char continue_input;printf("请输入要删除的姓名:");scanf("%s",name);while(p!=NULL){if(strcmp(p->name,name)==0) break;p=p->next;}if(p==NULL){printf("抱歉,没有该姓名的学生信息!\n");goto end;}elseprintf("确定要删除姓名为%s的学生的信息吗?(Y 确定;N 返回主菜单)",p->name);printf("\n");getchar();continue_input=getchar();if(continue_input=='y'||continue_input=='Y'){ppre=head;if(ppre==p){head=p->next;free(p);}else{while(ppre!=NULL){if(ppre->next==p){ppre->next=p->next;free(p);break;}ppre=ppre->next;}}printf("删除成功!");}//else Print_menu_main();end: printf("继续删除学生信息吗?(Y 继续;N 返回主菜单)");printf("\n");getchar();continue_input=getchar();if(continue_input=='Y'||continue_input=='y')Delete_record_by_name(head);else{system("cls");Print_menu_main();return head;}return 0;}struct student * Sorting_record_by_id(struct student *head)//按学号排序{int i=0,j,k,r;struct student *pt1,*pt2,*pt,m;if(head==NULL){printf("现在无同学记录\n");printf("(按Enter键返回主菜单)\n");getchar();r=getchar();if(r!='1'){system("cls");Print_menu_main();}else{system("cls");Print_menu_main();}}else{pt1=head;pt2=head->next;for(pt=head;pt;pt=pt->next)i++;for(j=1;j<i;j++){pt1=head;pt2=head->next;for(k=1;k<i-j+1;k++){if(pt1->num>pt2->num){m=*pt1;*pt1=*pt2;*pt2=m;pt2->next=pt1->next;pt1->next=pt2;}pt1=pt2;pt2=pt1->next;}}}print_table_head();for(pt=head;pt;pt=pt->next){printf("|%10d|%10s|%10s|%10d|%10d|\n",pt->num,pt->name,pt->birthday,pt->Cyuyan,pt->s hujujiegou);printf("+----------+----------+----------+----------+----------+\n");}return head;}int main(){struct student *head=NULL;struct student *p;int choice;int select;char m;char r;system("color e");printf("\n");printf("\n");printf(" 欢迎使用学生成绩管理系统!\n");printf("\n");printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^\n");printf("\n");printf("...............................................................................\n");printf("请按照提示信息完成操作\n");Print_menu_main();printf("\n");printf(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n");printf("\n");printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");while(choice!=0){printf("请选择所要执行的操作:\n");start:if(scanf("%d",&choice)){if(choice>7||choice<0){printf("请输入0到7的数字,选择所要执行的操作:\n");goto start;}elsegoto next;}if(scanf("%c",&m)){printf("请输入0到7的数字,选择所要执行的操作:\n");goto start;}next:switch(choice){case 1:system("cls");head=Creat_stu_record();break;case 2:system("cls");Print_Stu_Doc(head);break;case 3:system("cls");printf("请选择查找方式:1 按姓名查找;2 按学号查找;3 返回主菜单");printf("\n");scanf("%d",&select);switch(select){case 1:search_by_name(head);break;case 2:search_by_id(head);break;case 3:system("cls");Print_menu_main();break;};break;case 4:system("cls");printf("请输入修改方式:1 按学号修改;2 按姓名修改; 3 返回主菜单");printf("\n");scanf("%d",&select);switch(select){case 1:system("cls");modify_record_by_id(head);break;case 2:system("cls");modify_record_by_name(head);break;case 3:system("cls");Print_menu_main();break;}break;case 5:system("cls");head=insert_record(head);break;case 6:system("cls");printf("请输入删除方式:1 按学号删除;2 按姓名删除; 3 返回主菜单\n");scanf("%d",&select);switch(select){case 1:head=Delete_record_by_id(head);break;case 2:head=Delete_record_by_name(head);break;case 3:Print_menu_main();break;}break;case 7:system("cls");Sorting_record_by_id(head);printf("(按Enter键返回主菜单)\n");getchar();r=getchar();if(r!='1'){system("cls");Print_menu_main();}else{system("cls");Print_menu_main();}break;break;case 0:system("cls");printf("\n");printf("------------------------------------------------------------\n");printf(" ^-^ ^-^ ^-^ ^-^ ^-^ 谢谢使用^-^ ^-^ ^-^ ^-^ ^-^!\n");printf("\n");break;}}}三:代码第一部分:public class main {public static void main(String[] args) {zhuchuangkou win=new zhuchuangkou();}}第二部分主界面:import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;public class zhuchuangkou extends Frame implements ActionListener{Button button1,button2,button3,button4,tuichu;Panel p1,p2,p3;Label l1,l2,l3;TextField a1,a2;Box b1,b2,b3,b4,b5;ss s;zhuchuangkou(){button1=new Button("登陆");button2=new Button("删除");button3=new Button("修改");button4=new Button("添加");tuichu=new Button("退出");p1=new Panel();p2=new Panel();p3=new Panel();l1=new Label("学生成绩管理",Label.CENTER);l1.setFont(new Font("宋体",Font.BOLD,72));l1.setBackground(Color.green);l2=new Label("登录名");l3=new Label("密码");a1=new TextField(10);a2=new TextField(10);a2.setEchoChar('*');b1=Box.createVerticalBox();b1.add(l2);b1.add(Box.createVerticalStrut(8));b1.add(l3);b2=Box.createVerticalBox();b2.add(a1);b2.add(Box.createVerticalStrut(8));b2.add(a2);b4=Box.createHorizontalBox();b4.add(button1);b4.add(Box.createHorizontalStrut(10)); b4.add(tuichu);b3=Box.createHorizontalBox();b3.add(b1);b3.add(Box.createHorizontalStrut(10)); b3.add(b2);b5=Box.createVerticalBox();b5.add(b3);b5.add(Box.createVerticalStrut(8));b5.add(b4);button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this); button4.addActionListener(this);tuichu.addActionListener(this);p1.add(l1);p2.add(b5);add(p1,BorderLayout.NORTH);add(p2,BorderLayout.CENTER);add(p3,BorderLayout.PAGE_END);addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){dispose();}});setBackground(Color.RED);setBounds(10, 10, 1000, 500);setVisible(true);validate();}public void actionPerformed(ActionEvent e){if(e.getSource()==tuichu){System.exit(0);}if(e.getSource()==button1){if(a1.getText().equals("liuzhenji")&&a2.getText().equals("123456")){ new chuankou();System.out.println("wwwww");dispose();}else{System.out.print("nishurucuowu");}}}}第三部分选择操作:import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;public class zhuchuangkou extends Frame implements ActionListener{Button button1,button2,button3,button4,tuichu;Panel p1,p2,p3;Label l1,l2,l3;TextField a1,a2;Box b1,b2,b3,b4,b5;ss s;zhuchuangkou(){button1=new Button("登陆");button2=new Button("删除");button3=new Button("修改");button4=new Button("添加");tuichu=new Button("退出");p1=new Panel();p2=new Panel();p3=new Panel();l1=new Label("学生成绩管理",Label.CENTER);l1.setFont(new Font("宋体",Font.BOLD,72));l1.setBackground(Color.green);l2=new Label("登录名");l3=new Label("密码");a1=new TextField(10);a2=new TextField(10);a2.setEchoChar('*');b1=Box.createVerticalBox();b1.add(l2);b1.add(Box.createVerticalStrut(8));b1.add(l3);b2=Box.createVerticalBox();b2.add(a1);b2.add(Box.createVerticalStrut(8));b2.add(a2);b4=Box.createHorizontalBox();b4.add(button1);b4.add(Box.createHorizontalStrut(10));b4.add(tuichu);b3=Box.createHorizontalBox();b3.add(b1);b3.add(Box.createHorizontalStrut(10));b3.add(b2);b5=Box.createVerticalBox();b5.add(b3);b5.add(Box.createVerticalStrut(8));b5.add(b4);button1.addActionListener(this);button2.addActionListener(this);button3.addActionListener(this);button4.addActionListener(this);tuichu.addActionListener(this);p1.add(l1);p2.add(b5);add(p1,BorderLayout.NORTH);add(p2,BorderLayout.CENTER);add(p3,BorderLayout.PAGE_END);addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){dispose();}});setBackground(Color.RED);setBounds(10, 10, 1000, 500);setVisible(true);validate();}public void actionPerformed(ActionEvent e){if(e.getSource()==tuichu){System.exit(0);}if(e.getSource()==button1){if(a1.getText().equals("liuzhenji")&&a2.getText().equals("123456")){ new chuankou();System.out.println("wwwww");dispose();}else{System.out.print("nishurucuowu");}}}}第四部分查询界面实现:import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.JOptionPane;public class ss extends Frame implements TextListener,ActionListener{ Button xunzhao;TextField input;TextArea show;String s;int k;Connection con;Statement sql;int sum=0;ResultSet rs;ss(){Panel p=new Panel();xunzhao= new Button("查找");input= new TextField(10);show= new TextArea(6,43);p.add(new Label("输入学号"));p.add(input);p.add(xunzhao);xunzhao.addActionListener(this);show.addTextListener(this);show.setEditable(false);add(p,BorderLayout.NORTH);add(show,BorderLayout.CENTER);setBounds(10,30,500,200);setVisible(true);validate();addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){dispose();}});}public void actionPerformed(ActionEvent ee) {boolean boo=true;s=input.getText();k=Integer.parseInt(s);try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); }catch(ClassNotFoundException eee){ System.out.println(""+eee);}try { con=DriverManager.getConnection("jdbc:odbc:sun","gxy","123");sql=con.createStatement();rs=sql.executeQuery("SELECT * FROM chengjibiao ");while(rs.next()){int number=rs.getInt("number");String name=rs.getString("name");String date=rs.getString("birthday");int math=rs.getInt("math");int english=rs.getInt("english");if(number==k){ boo=false;show.setText(null);show.append("学号:"+number+" 姓名:"+name+" 出生:"+date+"数学"+math+" 英语"+english);show.append("\n");}}con.close();if(boo){JOptionPane.showMessageDialog(this, "你输入的学号不存在");}}catch(SQLException eee){ System.out.println(eee);}}}第五部分删除:import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.JOptionPane;public class shanchu extends Frame implements TextListener,ActionListener{ Button xunzhao;TextField input;TextArea show;String s;int k,s1,j;Connection con;Statement sql;int sum=0;ResultSet rs;shanchu(){Panel p=new Panel();xunzhao= new Button("删除");input= new TextField(10);show= new TextArea(6,43);p.add(new Label("输入要删除的" +"学号"));p.add(input);p.add(xunzhao);xunzhao.addActionListener(this);show.addTextListener(this);show.setEditable(false);add(p,BorderLayout.NORTH);add(show,BorderLayout.CENTER);setBounds(10,30,500,200);setVisible(true);validate();addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){dispose();}});}public void actionPerformed(ActionEvent ee) {boolean boo=true;s=input.getText();k=Integer.parseInt(s);String m,dir;try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException eee){ System.out.println(""+eee);}try { con=DriverManager.getConnection("jdbc:odbc:sun","gxy","123");sql=con.createStatement();rs=sql.executeQuery("SELECT * FROM chengjibiao");while(rs.next()){int number=rs.getInt(2);String name=rs.getString(3);String date=rs.getString("birthday");int math=rs.getInt("math");int english=rs.getInt("english");if(number==k){show.setText("你删除了:");show.append("学号:"+number+" 姓名:"+name+" 出生:"+date+"数学"+math+" 英语"+english);show.append("\n");m="DELETE FROM chengjibiao WHERE number="+k+"";sql.executeUpdate(m);}}con.close();}catch(SQLException e){ System.out.println(e);}}}第六部分修改:import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.JOptionPane;public class xiugai extends Frame implements TextListener,ActionListener{Button charu;TextField input1,input2,input3,input4,input5,input6;TextArea show;Panel p1,p2;int k,s1,j;Connection con;Statement sql;int sum=0;ResultSet rs;xiugai(){p1=new Panel();p2=new Panel();charu= new Button("修改");input1= new TextField(10);input2= new TextField(10);input3= new TextField(10);input4= new TextField(10);input5= new TextField(10);input6= new TextField(10);show= new TextArea(6,43);p1.add(new Label("请输入要修改的学号"));p1.add(new Label("number"));p1.add(input1);p2.add(new Label("请输入修改的数据"));p2.add(new Label("name"));p2.add(input2);p2.add(new Label("date"));p2.add(input3);p2.add(new Label("math"));p2.add(input4);p2.add(new Label("english"));p2.add(input5);p2.add(charu);charu.addActionListener(this);show.addTextListener(this);show.setEditable(false);add(p1,BorderLayout.NORTH);add(p2,BorderLayout.CENTER);setBounds(10,30,1200,200);setVisible(true);validate();addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){dispose();}});}public void actionPerformed(ActionEvent ee) { boolean boo=true;String s0,s1,s2,s3,s4,s5,insert1,recode,name,date;int m0,m1,m2,m3,number,math,english;s1=input1.getText();m1=Integer.parseInt(s1);number=m1;s4=input4.getText();m2=Integer.parseInt(s4);math=m2;s5=input5.getText();m3=Integer.parseInt(s5);english=m3;try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException eee){ System.out.println(""+eee);}try { con=DriverManager.getConnection("jdbc:odbc:sun","gxy","123");sql=con.createStatement();recode="("+m0+","+number+","+"'"+name+"'"+","+"'"+date+"'"+","+math+","+english+")";insert1="UPDA TE chengjibiao SET math="+math+",english="+english+"WHERE number="+number+"";sql.executeUpdate(insert1);} catch(SQLException e){ System.out.println(e);}}}第七部分添加:import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.JOptionPane;public class charu extends Frame implements TextListener,ActionListener{ Button charu;TextField input1,input2,input3,input4,input5,input6;TextArea show;int k,s1,j;Connection con;Statement sql;int sum=0;ResultSet rs;charu(){Panel p=new Panel();charu= new Button("插入");input1= new TextField(10);input2= new TextField(10);input3= new TextField(10);input4= new TextField(10);input5= new TextField(10);input6= new TextField(10);show= new TextArea(6,43);p.add(new Label("请输入要插入的数据"));p.add(new Label("ID"));。

Java实现简单的学生成绩管理系统

Java实现简单的学生成绩管理系统

Java实现简单的学⽣成绩管理系统ScoreInformation.javaimport java.util.Scanner;class ScoreInformation {private String stunumber; //⼋位学号private String name;private double mathematicsscore;private double englishscore;private double networkscore;private double databasescore;private double softwarescore;//构造函数ScoreInformation(String stunumber,String name,double mathematicssore,double englishscore,double networkscore,double databasescore,double softwarescore) {this.stunumber=stunumber;=name;this.mathematicsscore=mathematicssore;this.englishscore=englishscore;workscore=networkscore;this.databasescore=databasescore;this.softwarescore=softwarescore;};ScoreInformation(){};//读取和设置变量信息public void setstunumber(String stunumber){this.stunumber=stunumber;}public String getstunumber(){return stunumber;}public void setname(String name){=name;}public String getname(){return name;}public void setmathematicsscore(double math){this.mathematicsscore=math;}public double getmathematicsscore(){return mathematicsscore;}public void setenglishscore(double english){this.englishscore=english;}public double getenglishscore(){return englishscore;}public void setnetworkscore(double network){workscore=network;}public double getnetworkscore(){return networkscore;}public void setdatabasescore(double database){this.databasescore=database;}public double getdatebasescore(){return databasescore;}public void setsoftwarescore(double software){this.softwarescore=software;}public double getsoftwarescore(){return softwarescore;}}ScoreManagement.javaimport java.text.DecimalFormat;import java.util.Scanner;public class ScoreManagement {int t;public static void main(String[] args){ScoreManagement a=new ScoreManagement();ScoreInformation s[]=new ScoreInformation[5];//存储五个学⽣信息s[0]=new ScoreInformation("20183725","杨⽂青",0,0,0,0,0);s[1]=new ScoreInformation("20184725","乔⼀",70,70,70,70,70);s[2]=new ScoreInformation("20173695","沈潇",60,70,80,60,80);s[3]=new ScoreInformation("20183728","王⼀墨",70,70,70,70,70); s[4]=new ScoreInformation("20183721","肖奈",60,60,60,60,60);a.menu(s);}//主界⾯public void menu(ScoreInformation []s){System.out.println("***************************************");System.out.println(" ⽯家庄铁道⼤学软件⼯程系 ");System.out.println(" 学⽣学籍管理系统2019版 ");System.out.println("***************************************"); System.out.println(" 1.学⽣考试成绩录⼊ ");System.out.println(" 2.学⽣考试成绩修改 ");System.out.println(" 3.计算学⽣成绩绩点 ");System.out.println(" 4.退出学籍管理系统 ");System.out.println("***************************************");//输⼊选项int a;Scanner in=new Scanner(System.in);a=in.nextInt();while(a<0||a>4){System.out.print("输⼊⽆效,请重新输⼊:");a=in.nextInt();}switch(a) {case 1:add(s);break;case 2:modif(s);break;case 3:showjidian(s);case 4:exit();break;default:break;}}//退出界⾯public void exit(){System.out.println("**************************************************");System.out.println("谢谢使⽤⽯家庄铁道⼤学软件⼯程系学⽣学籍管理系统2019级版"); System.out.println(" 制作⼈:杨⽂青 ");System.out.println("**************************************************");System.exit(0);}//成绩录⼊,形参为数组public void add(ScoreInformation [] s){System.out.println("**************************************************");System.out.println(" ⽯家庄铁道⼤学软件⼯程系学⽣学籍管理系统2019级版");System.out.println("**************************************************");System.out.println(" 请输⼊学⽣学号(8位): ");Scanner in=new Scanner(System.in);int a;a=in.nextInt();for(int i=0;i<s.length;i++)if(a==Integer.parseInt(s[i].getstunumber())){this.luru(s);//录⼊完成后显⽰学⽣成绩信息System.out.println("**************************************************");System.out.println(" ⽯家庄铁道⼤学软件⼯程系学⽣学籍管理系统2019级版");System.out.println(" 学⽣考试成绩录⼊界⾯ ");System.out.println("**************************************************");System.out.println(" 学⽣学号:"+s[i].getstunumber());System.out.println(" 学⽣姓名:"+s[i].getname());System.out.println(" ⾼等数学成绩"+s[i].getmathematicsscore());System.out.println(" ⼤学英语成绩"+s[i].getenglishscore());System.out.println(" 计算机⽹络成绩"+s[i].getnetworkscore());System.out.println(" 数据库成绩"+s[i].getdatebasescore());System.out.println(" 软件⼯程成绩"+s[i].getsoftwarescore());System.out.println("该学⽣成绩已录⼊完毕,是否提交(Y/N)");System.out.println("**************************************************");Scanner In=new Scanner(System.in);String str;char ch;str=In.next();ch=str.charAt(0);while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n'){System.out.println("输⼊有误,请重新输⼊:");str=In.next();ch=str.charAt(0);}if(ch=='Y'||ch=='y'){this.menu(s);}if(ch=='N'||ch=='n'){this.luru(s);}}}//成绩成绩录⼊界⾯public void luru(ScoreInformation []s){System.out.println("**************************************************");System.out.println(" ⽯家庄铁道⼤学软件⼯程系学⽣学籍管理系统2019级版");System.out.println(" 学⽣考试成绩录⼊界⾯ ");System.out.println("**************************************************");System.out.println(" 学⽣学号:"+s[t].getstunumber()); //t是全局变量System.out.println(" 学⽣姓名:"+s[t].getname());System.out.println(" 请输⼊⾼等数学成绩: ");Scanner score=new Scanner(System.in);s[t].setmathematicsscore(score.nextDouble());System.out.println(" 请输⼊⼤学英语成绩: ");s[t].setenglishscore(score.nextDouble());System.out.println(" 请输⼊计算机⽹络成绩: ");s[t].setnetworkscore(score.nextDouble());System.out.println(" 请输⼊数据库成绩: ");s[t].setdatabasescore(score.nextDouble());System.out.println(" 请输⼊软件⼯程成绩: ");s[t].setsoftwarescore(score.nextDouble());System.out.println("**************************************************");}public void modif(ScoreInformation []s){System.out.println("**************************************************");System.out.println(" ⽯家庄铁道⼤学软件⼯程系学⽣学籍管理系统2019级版");System.out.println(" 学⽣考试成绩修改界⾯ ");System.out.println("**************************************************");System.out.println(" 请输⼊学⽣学号(8位): ");Scanner in=new Scanner(System.in);int a;a=in.nextInt();for(int i=0;i<s.length;i++)if(a==Integer.parseInt(s[i].getstunumber())){t=i; //标记该学⽣System.out.println("**************************************************");System.out.println(" ⽯家庄铁道⼤学软件⼯程系学⽣学籍管理系统2019级版"); System.out.println(" 学⽣考试成绩录⼊界⾯ ");System.out.println("**************************************************");System.out.println(" 学⽣学号:"+s[i].getstunumber());System.out.println(" 学⽣姓名:"+s[i].getname());System.out.println(" 1. ⾼等数学成绩"+s[i].getmathematicsscore());System.out.println(" 2. ⼤学英语成绩"+s[i].getenglishscore());System.out.println(" 3. 计算机⽹络成绩"+s[i].getnetworkscore());System.out.println(" 4. 数据库成绩"+s[i].getdatebasescore());System.out.println(" 5.软件⼯程成绩"+s[i].getsoftwarescore());System.out.println("**************************************************");}int m; //输⼊选项Scanner k=new Scanner(System.in);m=k.nextInt();System.out.println("**************************************************");System.out.println(" ⽯家庄铁道⼤学软件⼯程系学⽣学籍管理系统2019级版"); System.out.println(" 学⽣考试成绩录⼊界⾯ ");System.out.println("**************************************************");System.out.println(" 学⽣学号:"+s[t].getstunumber());System.out.println(" 学⽣姓名:"+s[t].getname());Scanner chengji=new Scanner(System.in); //录⼊所要修改的成绩if(m==1){ System.out.println(" 请输⼊修改后⾼等数学成绩");s[t].setmathematicsscore(chengji.nextDouble());}if(m==2){ System.out.println(" 请输⼊修改后⼤学英语成绩");s[t].setenglishscore(chengji.nextDouble());}if(m==3){ System.out.println(" 请输⼊修改后计算机⽹络成绩");s[t].setnetworkscore(chengji.nextDouble());}if(m==4){ System.out.println(" 请输⼊修改后数据库成绩");s[t].setdatabasescore(chengji.nextDouble());}if(m==5){ System.out.println(" 请输⼊修改后软件⼯程成绩");s[t].setsoftwarescore(chengji.nextDouble());}System.out.println("**************************************************");System.out.println(" ⽯家庄铁道⼤学软件⼯程系学⽣学籍管理系统2019级版"); System.out.println(" 学⽣考试成绩录⼊界⾯ ");System.out.println("**************************************************");System.out.println(" 学⽣学号:"+s[t].getstunumber());System.out.println(" 学⽣姓名:"+s[t].getname());System.out.println(" ⾼等数学成绩"+s[t].getmathematicsscore());System.out.println(" ⼤学英语成绩"+s[t].getenglishscore());System.out.println(" 计算机⽹络成绩"+s[t].getnetworkscore());System.out.println(" 数据库成绩"+s[t].getdatebasescore());System.out.println(" 软件⼯程成绩"+s[t].getsoftwarescore());System.out.println("该学⽣成绩已录⼊完毕,是否提交(Y/N)");System.out.println("**************************************************");Scanner In=new Scanner(System.in);String str;char ch;str=In.next();ch=str.charAt(0);while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n'){System.out.println("输⼊有误,请重新输⼊:");str=In.next();ch=str.charAt(0);}if(ch=='Y'||ch=='y'){this.menu(s);}if(ch=='N'||ch=='n'){this.modif(s);}}public double jidian(double n) //分数{//获得不同成绩段对应的绩点if(n>90) return 4.0;else if(n>=85) return 3.7;else if(n >=82) return 3.3;else if(n >=78) return 3.0;else if(n>=75) return 2.7;else if(n>=72) return 2.3;else if(n>=68) return 2.0;else if(n>=66) return 1.7;else if(n>=64) return 1.5;else if(n>=60) return 1.0;else return 0.;}public void showjidian(ScoreInformation []s){System.out.println("**************************************************");System.out.println(" ⽯家庄铁道⼤学软件⼯程系学⽣学籍管理系统2019级版"); System.out.println(" 学⽣考试成绩绩点计算界⾯ ");System.out.println("**************************************************");System.out.println(" 请输⼊学⽣学号:");Scanner in=new Scanner(System.in);int b;b=in.nextInt();//计算各学科绩点for(int i=0;i<5;i++){if(b==Integer.parseInt(s[i].getstunumber())){System.out.println("**************************************************");System.out.println(" ⽯家庄铁道⼤学软件⼯程系学⽣学籍管理系统2019级版"); System.out.println(" 学⽣考试成绩绩点计算界⾯ ");System.out.println("**************************************************");System.out.println(" 学⽣学号:"+s[i].getstunumber());System.out.println(" 学⽣姓名:"+s[i].getname());System.out.println(" ⾼等数学成绩绩点:"+jidian(s[i].getmathematicsscore()));System.out.println(" ⼤学英语成绩绩点:"+jidian(s[i].getenglishscore()));System.out.println(" 计算机⽹络成绩绩点:"+jidian(s[i].getnetworkscore()));System.out.println(" 数据库成绩绩点:"+jidian(s[i].getdatebasescore()));System.out.println(" 软件⼯程成绩绩点:"+jidian(s[i].getsoftwarescore()));//假设课程学分为1double avr=(jidian(s[i].getmathematicsscore())+jidian(s[i].getenglishscore())+jidian(s[i].getnetworkscore())+jidian(s[i].getdatebasescore())+jidian(s[i].getsoftwarescore()))/5; System.out.println(" 你的平均学分绩点为:"+new DecimalFormat("#.00").format(avr)); //⼩数点后保留两位if(avr>=2) System.out.println("提⽰信息:你的学分绩点已达到毕业要求!");else System.out.println("提⽰信息:你的学分绩点不满⾜毕业要求!");}}System.out.println("是否返回系统主界⾯(Y/N)");Scanner In=new Scanner(System.in);String str;char ch;str=In.next();ch=str.charAt(0);while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n'){System.out.println("输⼊有误,请重新输⼊:");str=In.next();ch=str.charAt(0);}if(ch=='Y'||ch=='y'){this.menu(s);}if(ch=='N'||ch=='n'){}}}实现的功能如下:。

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

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

JAVA课程设计学生信息管理系统代码某Tochangethitemplate,chooeTool|Template某andopenthetemplateintheeditor.某/packagetudentinfo;importjava.awt.某;importjava某.wing.某;importjava.awt.event.某;importjava.awt.某;importjava.awt.event.某;importjava.util.某;importjava某.wing.border.某;importjava某.wing.JOptionPane;importjava某.wing.JLabel;importjava某.wing.JPanel;importjava某.wing.table.DefaultTableModel; importjava某.wing.table.TableColumn;importjava.ql.某;importjava.awt.GridLayout;//网格式布局//导入javar需要的jar包publicclaStudentInfo{publicStudentInfo()//构造方法{}publictaticvoidmain(String[]arg){//TODOcodeapplicationlogichereloginFramelf=newloginFrame();//加载窗体lf.etViible(true);//设置窗体可见lf.addWindowLitener(newWindowAdapter()//添加窗口监听以接受关闭事件{publicvoidwindowCloing(WindowEvente){Sytem.e某it(0);}});}}//学生成绩管理系统界面clamainFramee某tendJFrameimplementActionLitener{MenuBarmyMenuBar=newMenuBar();//菜单MenuItemmiNew,miOpen,miSave,miSaveA,miE某it;MenuItemmiAdd,miEdit,miDel,miFind,miShow,miUer,miAbout;public JTabletable=newJTable();//表格publicDefaultTableModelmm;//表格模型publicmainFrame(){myMenuFile=newMenu("文件");miNew=newMenuItem("新建");miOpen=newMenuItem("打开");miSave=newMenuItem("保存");miE某it=newMenuItem("退出");//miNew.enable(fale);//miOpen.enable(fale);//miSave.enable(fa le);//myMenuFile.add(miNew);//myMenuFile.add(miOpen);//myMenuFil e.add(miSave);myMenuFile.add(miE某it);myMenuEdit=newMenu("数据编辑");miFind=newMenuItem("查找数据");miAdd=newMenuItem("添加数据");miEdit=newMenuItem("修改数据");miDel=newMenuItem("删除数据");miShow=newMenuItem("全部显示");myMenuEdit.add(miFind);myMenuEdit.add(miAdd);myMenuEdit.add(m iEdit);myMenuEdit.add(miDel);myMenuEdit.add(miShow);myMenuUer=ne wMenu("用户管理");miUer=newMenuItem("编辑用户");myMenuUer.add(miUer);myMenuAbout=newMenu("关于我");miAbout=newMenuItem("我的信息");myMenuAbout.add(miAbout);myMenuBar.add(myMenuFile);myMenuBar.add(myMenuEdit);myMenuBar.add(myMenuUer);myMenuBar.add(myMenuAbout);String[]col={"学号","姓名","性别","班级","专业","大学语文","大学英语","高等数学"};//创建属性列名table.etModel(mm);JScrollPanetableScrollPane=newJScrollPane( table);//设置滚动条thi.etMenuBar(myMenuBar);thi.add(tableScrollPane);miE某it.addActionLitener(thi);//为各按钮注册事件监听器对象miFind.addActionLitener(thi);miAdd.addActionLitener(thi);miEdit. addActionLitener(thi);miDel.addActionLitener(thi);miShow.addActi onLitener(thi);miUer.addActionLitener(thi);miAbout.addActionLite ner(thi);}publicvoidfrehTable(Stringql){myConnectionconn=newmyCo nnection();//获得数据库连接ReultSetr;//保存查询返回结果对象r=conn.getReult(ql);if(r!=null){try{mm.etRowCount(0);table.etMod el(mm);while(r.ne某t()){String学号=r.getString("学号");String姓名=r.getString("姓名");String性别=r.getString("性别");String班级=r.getString("班级");String专业=r.getString("专业");String大学语文=r.getString("大学语文");String大学英语=r.getString("大学英语");String高等数学=r.getString("高等数学");String[]cloumn={学号,姓名,性别,班级,专业,大学语文,大学英语,高等数学};mm.addRow(cloumn);}//table.clearSelection();table.etModel(mm );}catch(E某ceptione){}}}//捕获异常publicvoidactionPerformed(ActionEvente)//重载动作事件接口中的方法{//退出if(e.getSource()==miE某it){Sytem.e 某it(0);//查找}eleif(e.getSource()==miFind){findFrameff=newfindFrame(thi);ff .etViible(true);//添加}eleif(e.getSource()==miAdd){addFrameaf=newaddFrame(thi);af.et Viible(true);//修改}eleif(e.getSource()==miEdit){if(table.getSelectedRow()==-1){JOptionPane.howMeageDialog(null,"请选择你要修改的内容","温馨提示",RMATION_MESSAGE);//弹窗提示}{editFrameef=neweditFrame(thi);ef.学号.etTe某t((String)table.getValueAt(table.getSelectedRow(),0));ef.姓名.etTe某t((String)table.getValueAt(table.getSelectedRow(),1));ef.性别.etTe某t((String)table.getValueAt(table.getSelectedRow(),2));ef.班级.etTe某t((String)table.getValueAt(table.getSelectedRow(),3));ef.专业.etTe某t((String)table.getValueAt(table.getSelectedRow(),4));ef.大学语文.etTe某t((String)table.getValueAt(table.getSelectedRow(),5));ef.大学英语.etTe某t((String)table.getValueAt(table.getSelectedRow(),6));ef.高等数学.etTe某t((String)table.getValueAt(table.getSelectedRow(),7));ef.etViibl e(true);thi.frehTable("elect某from学生成绩表");//刷新表格}//删除eleif(e.getSource()==miDel){if(table.getSelectedRow()==-1){JOptionPane.howMeageDialog(null,"请选择你要删除的行","温馨提示",RMATION_MESSAGE);}ele{Stringql="deletefrom学生成绩表where学号='"+table.getValueAt(table.getSelectedRow(),0)+"'";//JOptionPane.howMeageDialog(null,ql,"温馨提示",RMATION_MESSAGE);myConnectionconn=newmyConnection();if(conn.e某ecuteSql(ql)){JOptionPane.howMeageDialog(null,"成功删除","温馨提示",RMATION_MESSAGE);thi.frehTable("elect某from学生成绩表");ele{JOptionPane.howMeageDialog(null,"未知错误","删除失败",RMATION_MESSAGE);}}//显示}eleif(e.getSource()==miShow){//JOptionPane.howMeageDialog(null,"未知错误","删除失败",RMATION_MESSAGE);thi.frehTable("elect某from学生成绩表");//编辑用户}eleif(e.getSource()==miUer){uerFrameuf=newuerFrame();uf.etViible(true);//作业说明}eleif(e.getSource()==miAbout){aboutFrameaf=newaboutFrame();af.etViible(true);}}}clamyConnection{ReultSetre;Stringtrurl="jdbc:odbc:driver={MicrooftAcceDriver(某.mdb)};D BQ=学生管理数据库.mdb";//Stringtrurl="jdbc:odbc:driver={MicrooftAcceDriver(某.mdb)} ;DBQ=学生管理数据库.mdb";//Stringtrurl="jdbc:odbc:cah";//cah为数据源名称publicmyConnection(){}publicReultSetgetReult(Stringql){try{Cla.forName("un.jdbc.odbc.JdbcOdbcDriver");Connectionconn=DriverManager.getConnection(trurl);Statementtmt=conn.createStatement(ReultSet.TYPE_SCROLL_SENSITIVE,Reul tSet.CONCUR_UPDATABLE);ReultSetre=tmt.e某ecuteQuery(ql);returnre;}catch(E某ceptione){e.printStackTrace();//异常处理returnnull;}}publicbooleane某ecuteSql(Stringql){try{Cla.forName("un.jdbc.odbc.JdbcOdbcDriver"); Connectionconn=DriverManager.getConnection(trurl); Statementtmt=conn.createStatement();tmt.e某ecuteUpdate(ql);mit();returntrue;}catch(E某ceptione){e.printStackTrace();returnfale;}}}claaddFramee某tendJDialogimplementActionLitener {publictaticfinalintWIDTH=400;publictaticfinalintHEIGHT=400;JLabel学号1,姓名1,性别1,班级1,专业1,大学语文1,大学英语1,高等数学1;JTe某tField学号,姓名,性别,班级,专业,大学语文,大学英语,高等数学;JButtonb;JPanelp;mainFramemf;publicaddFrame(mainFramemmf){etT itle("添加学生成绩");etSize(WIDTH,HEIGHT);etLocation(120,180);ContainercontentPane =getContentPane();//创建一个容器对象contentPane.etLayout(newFlowLayout());//流式布局学号1=newJLabel("学号");姓名1=newJLabel("姓名");性别1=newJLabel("性别");班级1=newJLabel("班级");专业1=newJLabel("专业");大学语文1=newJLabel("大学语文");大学英语1=newJLabel("大学英语");高等数学1=newJLabel("高等数学");学号=newJTe某tField(5);姓名=newJTe某tField(5);性别=newJTe某tField(5);班级=newJTe某tField(5);专业=newJTe某tField(5);大学语文=newJTe某tField(5);大学英语=newJTe 某tField(10);高等数学=newJTe某tField(10);b=newJButton("确定");p=newJPanel();p.etLayout(newGridLayout(10,2,5,5));//表格布局p.add(学号1);p.add(学号);p.add(姓名1);p.add(姓名);p.add(性别1);p.add(性别);p.add(班级1);p.add(班级);p.add(专业1);p.add(专业);p.add(大学语文1);p.add(大学语文);p.add(大学英语1);p.add(大学英语);p.add(高等数学1);p.add(高等数学);p.add(newLabel(""));p.add(newLabel(""));p.add(b);contentPane .add(p);//添加按钮监听器b.addActionLitener(thi);mf=mmf;}publicvoidactionPerformed(ActionEvente){if(学号.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入学号","温馨提示",RMATION_MESSAGE);}eleif(姓名.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入姓名","温馨提示",RMATION_MESSAGE);}eleif(大学语文.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入大学语文","温馨提示",RMATION_MESSAGE);}ele{Stringql="elect某from学生成绩表where学号='"+学号.getTe某t()+"'";myConnectionconn=newmyConnection();ReultSetr;r=conn.getReult (ql);try{//Sytem.out.println(r.getRow());if(r.ne某t()){ JOptionPane.howMeageDialog(null,"此学号已经存在","温馨提示",RMATION_MESSAGE);误信息}//添加学生的时候,发现数据库已经有了,提示你学号已经存在,报错ele{ql="inertinto学生成绩表value('"+学号.getTe某t()+"','"+姓名.getTe某t()+"','"+性别.getTe某t()+"','"+班级.getTe某t()+"','"+专业.getTe某t()+"','"+大学语文.getTe某t()+"','"+大学英语.getTe某t()+"','"+高等数学.getTe某t()+"')";//实行数据库插入的语句if(conn.e某ecuteSql(ql))//插入语句{JOptionPane.howMeageDialog(null,"添加成功","温馨提示",RMATION_MESSAGE);}ele{mf.frehTable("elect某from学生成绩表");学号.etTe某t("");姓名.etTe某t("");性别.etTe某t("");班级.etTe某t("");专业.etTe某t("");大学语文.etTe某t("");大学英语.etTe某t("");高等数学.etTe某t("");JOptionPane.howMeageDialog(null,"添加失败","温馨提示",RMATION_MESSAGE);}//插入失败}}catch(E某ceptioner){Sytem.out.println(er.toString());}}}}claeditFramee某tendJDialogimplementActionLitener{publictaticfinalintWIDTH=400;publictaticfinalintHEIGHT=400;JLabel学号1,姓名1,性别1,班级1,专业1,大学语文1,大学英语1,高等数学1;JTe某tField学号,姓名,性别,班级,专业,大学语文,大学英语,高等数学;JButtonb;JPanelp;mainFramemf;publiceditFrame(mainFramemmf){et Title("修改学生信息");etSize(WIDTH,HEIGHT);etLocation(120,180);ContainercontentPane =getContentPane();contentPane.etLayout(newFlowLayout());学号1=newJLabel("学号");姓名1=newJLabel("姓名");性别1=newJLabel("性别");班级1=newJLabel("班级");专业1=newJLabel("专业");大学语文1=newJLabel("大学语文");大学英语1=newJLabel("大学英语");高等数学1=newJLabel("高等数学");学号=newJTe某tField(5);姓名=newJTe某tField(5);性别=newJTe某tField(5);班级=newJTe某tField(5);专业=newJTe某tField(5);大学语文=newJTe某tField(5);大学英语=newJTe 某tField(10);高等数学=newJTe某tField(10);学号.etEnabled(fale);b=newJButton("确定");p=newJPanel();p.etLayout(newGridLayout(10,2,5,5));p.add(学号1);p.add(学号);p.add(姓名1);p.add(姓名);p.add(性别);p.add(班级1);p.add(班级);p.add(专业1);p.add(专业);p.add(大学语文1);p.add(大学语文);p.add(大学英语1);p.add(大学英语);p.add(高等数学1);p.add(高等数学);p.add(newLabel(""));p.add(newLabel(""));p.add(b);contentPane .add(p);//添加按钮监听器b.addActionLitener(thi);mf=mmf;}//这是画界面publicvoidactionPerformed(ActionEvente){if(学号.getTe某t().toString().equal(""))//判断{JOptionPane.howMeageDialog(null,"请输入学号","温馨提示",RMATION_MESSAGE);//弹出的小窗口提示}eleif(姓名.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入姓名","温馨提示",RMATION_MESSAGE);}eleif(大学语文.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入大学语文","温馨提示",RMATION_MESSAGE);}ele{Stringql="update学生成绩表et姓名='"+姓名.getTe某t()+"',性别='"+性别.getTe某t()+"',班级='"+班级.getTe某t()+"',专业='"+专业.getTe某t()+"',大学语文='"+大学语文.getTe某t()+"',大学英语='"+大学英语.getTe某t()+"',高等数学='"+高等数学.getTe某t()+"'where学号='"+学号.getTe某t()+"'";myConnectionconn=newmyConnection();//打开数据库的连接try{//JOptionPane.howMeageDialog(null,ql,"温馨提示",RMATION_MESSAGE);if(conn.e某ecuteSql(ql))//执行ql语句,弹出窗口,查询学生表刷新table{JOptionPane.howMeageDialog(null,"修改成功","温馨提示",RMATION_MESSAGE);mf.frehTable("elect某from学生成绩表");thi.dipoe();//关闭当前窗体对象,隐藏}ele{JOptionPane.howMeageDialog(null,"修改失败","温馨提示",RMATION_MESSAGE);}}catch(E某ceptioner){er.printStackTrace();}}}}clafindFramee某tendJDialogimplementActionLitener{mainFramemf;JPanelp;JTe某tFieldt;JButtonb;JButtonfAll;Stringql="elect某fromtudent";String[]colStr={"学号","姓名","性别","班级","专业","大学语文","大学英语","高等数学"};publicfindFrame(mainFramemmf) {mf=mmf;p=newJPanel();t=newJTe某tField(10);b=newJButton("查找");fAll=newJButton("全部显示");b.addActionLitener(thi);fAll.addActionLitener(thi);p.add(newJLabel("选择"));p.add(c);p.add(newJLabel("查找内容"));p.add(t);p.add(b);p.add(fAll);thi.add(p);thi.etTitle("查找");thi.etSize(450,80);}publicvoidactionPerformed(ActionEvente){//查找if(e.getSource()==b){StringelectStr=c.getSelectedItem().toString(); if(electStr=="大学英语"){ql="elect某from学生成绩表"+t.getTe某t().toString();}ele{ql="elect某from学生成绩表'"+t.getTe某t().toString()+"'";}mf.frehTable(ql);//全部显示}if(e.getSource()==fAll){ql="elect某from学生成绩表";mf.frehTable(ql);}//监听程序,选择查成绩,最后是重新刷新table }}claaboutFramee某tendJDialog//关于我的信息{aboutFrame(){JPanelp1=newJPanel();where"+electStr+"where"+electStr+"== clauerFramee某tendJFrameimplementActionLitener//用户密码{JTe某tFielduer,pa;JButtonadd,del;JTablet;JPanelp1,p2,p3,p4,p5;DefaultTableModelm;publicuerFrame(){p1=newJPanel();p2=newJPanel();p3=newJPanel();p4=newJPanel();p5=newJPanel();uer=newJTe某tField(8);pa=newJTe某tField(8);add=newJButton("添加");del=newJButton("删除");String[]col={"用户名","密码"};m=newDefaultTableModel(col,0);t=newJTable();t.etModel(m);JScr ollPanep=newJScrollPane(t);p1.add(newJLabel("用户名"));p1.add(uer);p1.add(newJLabel("密码"));p1.add(pa);p1.add(add);p2.add(p);p3.add(del);add.addActionLi tener(thi);del.addActionLitener(thi);myConnectionconn=newmyConne ction();ReultSetr;r=conn.getReult("elect某from管理员");//开始时连接数据库,查询数据,返回结果集,if(r!=null){//把查询结果放到table里面try{//m.etRowCount(0);//table.etModel(mm);while(r.ne某t()){String用户名=r.getString("用户名");String密码=r.getString("密码");String[]cloumn={用户名,密码};m.addRow(cloumn);}t.etModel(m);}catch(E某ceptione){Sytem.out.println(e.toString());}}thi.add(p1,BorderLay out.NORTH);thi.add(p2,BorderLayout.CENTER);thi.add(p3,BorderLayo ut.SOUTH);thi.add(p4,BorderLayout.WEST);thi.add(p5,BorderLayout. EAST);thi.etTitle("用户管理");thi.etSize(600,400);}publicvoidactionPerformed(ActionEvente){ //用户添加if(e.getSource()==add){if(uer.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入用户名","温馨提示",RMATION_MESSAGE);eleif(pa.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入密码","温馨提示",RMATION_MESSAGE);}elemyConnectionconn=newmyConnection();ReultSetr;try{r=conn.getReult("elect某from管理员where用户名='"+uer.getTe某t().toString()+"'");if(r.ne某t()){JOptionPane.howMeageDialog(null,"此用户已经存在","温馨提示",RMATION_MESSAGE);}ele{if(conn.e某ecuteSql("inertinto管value('"+uer.getTe某t().toString()+"','"+pa.getTe某t().toString()+"')"))String[]newUer={uer.getTe某t(),pa.getTe某t()};m.addRow(newUer);t.etModel(m);理员JOptionPane.howMeageDialog(null,"添加成功","温馨提示",RMATION_MESSAGE);}ele{JOptionPane.howMeageDialog(null,"添加失败","温馨提示",RMATION_MESSAGE);}}}catch(E某ceptioner){Sytem.out.println(er.toString());}}//删除}eleif(e.getSource()==del){if(t.getSelectedRow()==-1){JOptionPane.howMeageDialog(null,"请选择你要删除的行","温馨提示",RMATION_MESSAGE);}ele{=",Stringql="deletefrom管理员where用户名'"+t.getValueAt(t.getSelectedRow(),0)+"'";//JOptionPane.howMeage Dialog(null,ql,"温馨提示RMATION_MESSAGE);myConnectionconn=newmyConnection();if(conn.e某ecuteSql(ql)){m.removeRow(t.getSelectedRow());t.etModel(m);//t.removeRowSelectionInterval();JOptionPane.howMeageDialog(null,"成功删除","温馨提示",RMATION_MESSAGE);}ele{JOptionPane.howMeageDialog(null,"未知错误","删除失败",RMATION_MESSAGE);}}}}}claloginFramee某tendJDialogimplementActionLitener//登陆{JPanelp;JTe某tFielduer,pa;JButtonlogin,cancel;publicloginFrame(){p=newJPanel();uer=newJTe某tField(10);pa=newJTe某tField(10);login=newJButton("登录");cancel=newJButton("退出");uer.etTe某t("");pa.etTe某t("");login.addActionLitener(thi);cancel.addActionLitener(thi);p.add(newJLabel("账号"));p.add(uer);p.add(newJLabel("密码"));p.add(pa);p.add(login);p.add(cancel);thi.add(p);thi.etTitle("学生成绩管理系统");JLabelimg=newJLabel(newImageIcon("1.jpg"));p.add(img);thi.etSize(700,600);}publicvoidactionPerformed(ActionEvente){//查找if(e.getSource()==login){if(uer.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入用户名","温馨提示",RMATION_MESSAGE);}eleif(pa.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入密码","温馨提示",RMATION_MESSAGE);}ele{myConnectionconn=newmyConnection();ReultSetr;Stringql="elect某from管理员where用户名='"+uer.getTe某t().toString()+"'and密码='"+pa.getTe某t().toString()+"'";try{r=conn.getReult(ql);if(r.ne某t()){thi.dipoe();//JOptionPane.howMeageDialog(null,"此用户已经存在","温馨提示",RMATION_MESSAGE);ql="elect某from学生成绩表";mainFramemf=newmainFrame();mf.etTitle("学生成绩管理系统");mf.etSize(600,486);mf.frehTable(ql);mf.etViible(true);mf.addWindowLitener(newWindowAdapter(){publicvoidwindowCloing(WindowEvente){Sytem.e某it(0);}});}ele{JOptionPane.howMeageDialog(null,"用户名或密码错误","登录失败",RMATION_MESSAGE);}}catch(E某ceptioner){Sytem.out.println(er.toString());}}}}//全部显示}if(e.getSource()==cancel){Sytem.e某it(0);}。

基于JAVA的学生成绩管理系统源代码(1)

基于JAVA的学生成绩管理系统源代码(1)

Java程序设计系专业班级学号15号姓名刘振基题目学生成绩管理系统任课教师彭杰一:要求1、用到书上(课本或实验册)上的至少三个实例2、用到至少两种布局和至少四种组件3、用到对话框4、用到对数据库的查询、删除、添加和修改5、最好用到输入输出流6、具有一定的实际意义二:内容本系统用access作为数据库,用到了书上的布局实例和数据库连接实例功能: 1、输入十个同学的学号,姓名,出生日期,二科成绩(学,大学英语) .2、输入学号查询学生信息.3、删除记录4、查询记录5、添加记录6、修改记录三:代码第一部分:public class main {public static void main(String[] args){zhuchuangkou win=new zhuchuangkou();}}第二部分主界面:import java.awt。

*;import java.awt.event。

*;import javax。

swing.*;import javax。

swing。

border。

*;public class zhuchuangkou extends Frame implements ActionListener{Button button1,button2,button3,button4,tuichu;Panel p1,p2,p3;Label l1,l2,l3;TextField a1,a2;Box b1,b2,b3,b4,b5;ss s;zhuchuangkou(){button1=new Button(”登陆”);button2=new Button("删除”);button3=new Button(”修改”);button4=new Button(”添加");tuichu=new Button(”退出");p1=new Panel();p2=new Panel();p3=new Panel();l1=new Label("学生成绩管理”,Label.CENTER);l1.setFont(new Font("宋体",Font.BOLD,72));l1。

(完整word版)用java做的简短学生成绩管理系统(不连接数据库)

(完整word版)用java做的简短学生成绩管理系统(不连接数据库)

import java.util.*;public class Main {String[] N= new String[100];String[] I=new String[100];int[] A=new int[100];String[] S=new String[100];String[] Z=new String[100];int[] C=new int[100];int[] M=new int[100];int[] E=new int[100];int i;public class person{Scanner src=new Scanner(System.in);String[] name= new String[100];String[] id=new String[100];int[] age=new int[100];String[] sex=new String[100];}public void caidan(){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("7——退出");}public void luru(){xuesheng guanli1=new xuesheng();guanli1.luru();}public void chaxun(){xuesheng guanli1=new xuesheng();guanli1.chaxun();}public void zengjia(){xuesheng guanli1=new xuesheng();guanli1.zengjia();}public void shanchu(){xuesheng guanli1=new xuesheng();guanli1.shanchu();}public void xiugai(){xuesheng guanli1=new xuesheng();guanli1.xiugai();}public void chaxun1(){xuesheng guanli1=new xuesheng();guanli1.chaxun1();}public void denglu(){Scanner src=new Scanner(System.in);int s;String q;System.out.println("请先登录系统!");System.out.println("1——学生登录2——教师登录");s=src.nextInt();if(s==1){System.out.println("请输入密码:(xuesheng)");q=src.next();if(q.equals("xuesheng")){zhixing();}else{System.out.println("请确认后重新登录登陆!!!");denglu();}}else{if(s==2){System.out.println("请输入密码:(jiaoshi)");q=src.next();if(q.equals("jiaoshi")){zhixing();}else{System.out.println("请确认后重新登录登陆!!!");denglu();}}}}public void zhixing(){Scanner src=new Scanner(System.in);Main guanli=new Main();int m=0;int t=0;while(m!=4){switch(t){case 0:guanli.caidan();System.out.println("请输入相应编号完成操作:");t=src.nextInt();break;case 1:guanli.luru();guanli.caidan();System.out.println("请输入相应编号完成操作:");t=src.nextInt();break;case 2:guanli.chaxun();guanli.caidan();System.out.println("请输入相应编号完成操作:");t=src.nextInt();break;case 3:guanli.xiugai();guanli.caidan();System.out.println("请输入相应编号完成操作:");t=src.nextInt();break;case 4:guanli.shanchu();guanli.caidan();System.out.println("请输入相应编号完成操作:");t=src.nextInt();break;case 5:guanli.zengjia();guanli.caidan();System.out.println("请输入相应编号完成操作:");t=src.nextInt();break;case 6:guanli.chaxun1();guanli.caidan();System.out.println("请输入相应编号完成操作:");t=src.nextInt();break;case 7:m=4;}}}public class xuesheng extends person{private String[] zybj=new String[100];private int[] chinese=new int[100];private int[] math=new int[100];private int[] english=new int[100];public void luru(){int r;System.out.println("请输入原始学生人数:");r=src.nextInt();i=r;for(int t=0 ;t<i;t++){System.out.println("请输入学生姓名:");N[t]=name[t]=src.next();System.out.println("请输入学生学号:");I[t]=id[t]=src.next();System.out.println("请输入学生性别:");S[t]=sex[t]=src.next();System.out.println("请输入学生年龄:");A[t]=age[t]=src.nextInt();System.out.println("请输入学生专业班级:");Z[t]=zybj[t]=src.next();System.out.println("语文成绩:");C[t]=chinese[t]=src.nextInt();System.out.println("数学成绩:");M[t]=math[t]=src.nextInt();System.out.println("英语成绩:");。

用java编写的学生成绩管理系统代码

用java编写的学生成绩管理系统代码

//studentimport java。

sql.*;public class Student{private String id;private String name;private int math;private int english;private int java;private int computer;public String getId(){return id;}public void setId(String id){this.id = id;}public String getName(){return name;}public void setName(String name){this。

name = name;}public int getMath(){return math;}public void setMath(int math){this。

math = math;}public int getEnglish(){return english;}public void setEnglish(int english){this。

english = english;}public int getJava(){return java;}public void setJava(int java){this.java = java;}public int getComputer(){return computer;}public void setComputer(int computer){this。

computer = computer;}public static void main(String[]args)throws Exception{String id;String cid;String name;int math;int english;int java;int computer;String DBDriver = ”sun。

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

;
public class Student
{
private String id;
private String name;
private int math;
private int english;
private int java;
private int computer;
public String getId()
{
return id;
}
public void setId(String id)
{
= id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
= name;
}
public int getMath()
{
return math;
}
public void setMath(int math)
{
= math;
}
public int getEnglish()
{
return english;
}
public void setEnglish(int english) {
= english;
}
public int getJava()
{
return java;
}
public void setJava(int java)
{
= java;
}
public int getComputer()
{
return computer;
}
public void setComputer(int computer)
{
= computer;
}
public static void main(String[] args) throws Exception {
String id;
String cid;
String name;
int math;
int english;
int java;
int computer;
String DBDriver = "";
String conStr = "jdbc:odbc:student";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
(DBDriver);
con = (conStr, "student", "123");
stmt = ();
String s = "\n\n\t\t\t学生成绩\n\n\t\t 1 新增\n\t\t 2 更改\n\t\t 3 删除\n\t\t 4 查找\n\t\t 5 显示\n\t\t 0 退出\n\n";
int choice = ();
switch (choice)
{
xecuteQuery("select avg(math),avg(english),avg(java),avg(computer) from lxh1");
while ())
{
+ "\t" + (2) + "\t"
+ (3) + "\t" + (4));
}
;
xecuteQuery("select min(math),min(english),min(java),min(computer) from lxh1");
while ())
{
+ "\t" + (2) + "\t"
+ (3) + "\t" + (4));
}
;
break;
case 0:
break;
default:
"感谢您的使用,再见!");
}
;
();
();
}
}。

相关文档
最新文档