您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > JAVA学生成绩管理系统源码
文件addmessage.java代码:importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjava.util.*;importjavax.swing.*;importjavax.swing.table.*;classaddmessageextendsJFrameimplementsActionListener{JTextFieldt1,t2,t3,t4,t5;JTabletable;JButtonbut1;JLabellab1,lab2,lab3,lab4,lab5;JPanelp1;addmessage(){super(增加);setBounds(350,100,470,400);setLayout(newGridLayout(1,1,10,10));p1=newJPanel();lab1=newJLabel(学号);t1=newJTextField(10);lab2=newJLabel(姓名);t2=newJTextField(10);lab3=newJLabel(课程名);t3=newJTextField(10);lab4=newJLabel(状态);t4=newJTextField(10);lab5=newJLabel(成绩);t5=newJTextField(10);but1=newJButton(添加);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);}publicvoidactionPerformed(ActionEvente){inti=0;Stringsql1=null,sql2=null,update=null;Stringurl=jdbc:mysql://localhost:3306/学生成绩系统;Connectioncon;Statementstmt;try{Class.forName(org.gjt.mm.mysql.Driver);}catch(java.lang.ClassNotFoundExceptione1){System.err.println(ClassNotFoundException:+e1.getMessage());}if(e.getSource()==but1){//添加-------------------try{con=DriverManager.getConnection(url,root,123);stmt=con.createStatement();sql1=INSERTINTO学生成绩表VALUES('+t1.getText()+','+t2.getText()+','+t3.getText()+','+t4.getText()+','+t5.getText()+');Stringnum1=t1.getText();Stringnum2=t1.getText();Stringsele=select*from学生成绩表where学号='+num1+'and课程名='+num2+';ResultSetrs=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(SQLExceptionex){System.err.println(SQLException:+ex.getMessage());}}}}文件deletemessage.java代码importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjava.util.*;importjavax.swing.*;importjavax.swing.table.*;classdeletemessageextendsJFrameimplementsActionListener{JTextFieldt1,t2,t3;JTabletable;JButtonbut1;JLabellab1,lab2,lab3;JPanelp1;deletemessage(){super(删除);setBounds(350,100,470,400);setLayout(newGridLayout(1,1,10,10));p1=newJPanel();lab1=newJLabel(学号);t1=newJTextField(10);lab2=newJLabel(姓名);t2=newJTextField(10);lab3=newJLabel(课程名);t3=newJTextField(10);but1=newJButton(删除);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);}publicvoidactionPerformed(ActionEvente){Stringsql1=null,sql2=null;Stringurl=jdbc:mysql://localhost:3306/学生成绩系统;Connectioncon;Statementstmt;try{Class.forName(org.gjt.mm.mysql.Driver);}catch(java.lang.ClassNotFoundExceptione1){System.err.println(ClassNotFoundException:+e1.getMessage());}if(e.getSource()==but1){//删除----------------------------try{Stringnum1=t1.getText();Stringnum2=t2.getText();Stringnum3=t3.getText();sql2=deletefrom学生成绩表where学号='+num1+'and课程名='+num3+';con=DriverManager.getConnection(url,root,123);stmt=con.createStatement();sql1=select*from学生成绩表where学号='+num1+'and姓名='+num2+'and课程名='+num3+';ResultSetrs=stmt.executeQuery(sql1);if(rs.next()){stmt.executeUpdate(sql2);JOptionPane.showMessageDialog(this,删除成功!);}else{JOptionPane.showMessageDialog(this,没有此条记录!请重新输入);}t1.setText();stmt.close();con.close();}catch(SQLExceptionex){System.err.println(SQLException:+ex.getMessage());}}}}文件entry.java代码importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax.swing.*;classentryextendsJFrameimplementsActionListener{intflag=1;Stringuser,pass;JPanelpa;JLabellab1,lab2;JTextFieldtf1;JPasswordFieldtf2;JButtonbtu1,btu2;JPanelpa1,pa2,pa4;entry(){super(学生成绩管理系统);setBounds(400,200,400,300);GridBagLayoutgbL=newGridBagLayout();GridBagConstraintsgbc=newGridBagConstraints();setLayout(gbL);gbc.fill=GridBagConstraints.HORIZONTAL;gbc.anchor=GridBagConstraints.CENTER;lab1=newJLabel(请输入帐号);lab2=newJLabel(请输入密码);tf2=newJPasswordField(10);tf2.setEchoChar('*');tf1=newJTextField(10);tf1.addActionListener(this);pa1=newJPanel();pa1.add(lab1);pa1.add(tf1);gbc.gridx=1;gbc.gridy=1;gbc.insets=newInsets(2,5,0,5);gbL.setConstraints(pa1,gbc);add(pa1);tf2.addActionListener(this);pa2=newJPanel();pa2.add(lab2);pa2.add(tf2);gbc.gridx=1;gbc.gridy=2;gbc.insets=newInsets(2,5,2,5);gbL.setConstraints(pa2,gbc);add(pa2);btu1=newJButton(确定);btu1.addActionListener(this);btu2=newJButton(退出);btu2.addActionListener(this);pa4=newJPanel();pa4.add(btu1);pa4.add(btu2);gbc.gridx=1;gbc.gridy=4;gbc.insets=newInsets(2,5,2,5);gbL.setConstraints(pa4,gbc);add(pa4);}publicvoidactionPerformed(ActionEvente){loginsurels;if(e.getSource()==btu1){user=tf1.getText();pass=tf2.getText();try{ls=newloginsure(user,pass);this.setVisible(false);}catch(SQLExceptione1){e1.printStackTrace();}catch(ClassNotFoundExceptione1){e1.printStackTrace();}}if(e.getSource()==btu2){dispose();System.exit(0);}}}classloginsure{inti=0;Stringname=null,pwd=null,ustype=null;publicloginsure(Strings,Stringa)throwsSQLException,ClassNotFoundException{Stringdriver=org.gjt.mm.mysql.Driver;Class.forName(driver);
本文标题:JAVA学生成绩管理系统源码
链接地址:https://www.777doc.com/doc-5554507 .html