Freshman project training — Student achievement management system

<> Project training summary

Because I am a freshman Java I didn't listen well in class , Lead to the project training is learning at the same time knock code . But I made a lot of efforts , morning 8.30 get up , night 2,3 I didn't go to bed until midnight or even all night , Although they are very basic things , But if you don't listen well in class, you have to work hard ( Heavy price ).

<> Mainly responsible for

one , Design of main panel
two , Student information , Teacher information , The management of students' achievement

<> Part code

Mainly used the student information (studentinfo) Student achievement (studentgrade) Two Mysql Table for ,
The function is to add, delete and modify the table , That is, enter the student's score , Revise student grades , Delete student grades, etc .
Then there are the foreign keys of various tables, which are really troublesome , When entering student grades , It is necessary to judge whether the student exists or not , And judge whether there are restrictions on changing subjects when modifying students' scores .

<> make efforts

study Java It's still shallow , I'll make up for it in summer vacation . My teammates helped me revise it many times bug It's over , I'm really sorry . Next semester PHP,Mysql And enterprise class web Application development must study hard .
package StudentManage; import java.awt.Button; import java.awt.Choice; import
java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridLayout;
import java.awt.Label; import java.awt.Panel; import java.awt.TextField; import
java.awt.Toolkit; import java.awt.event.ActionEvent; import
java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import
java.awt.event.WindowEvent; import java.sql.ResultSet; import
java.sql.SQLException; import java.util.Vector; import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JScrollPane; import
javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class
GradeChange extends JFrame implements ActionListener { Label sid1, sid2, sb1,
empty,empty1,empty2,empty3,classcode; Label name1, subject1, studentgrade1 ;
TextField sid11, sid22; TextField name2, subject2, studentgrade2,classcode1;
Choice choice; JFrame jFrame; Button look, refresh, delete, submit, reset,
exit, add, change, help,delete1,reset1,submit1,back; String string; ResultSet
rs = null; // Query template and scrolling interface DefaultTableModel model; JScrollPane check, check1;
JTable jTable1, jTable2; Panel panel0,panel1,panel2,panel3,panel4; public
GradeChange() { super(" Student achievement management "); toppanel(); table(DBHelper.query("select *
from studentgrade order by sid ")); // Initial panel display information mainpanel(); // // Set up the monitor
setSize(450, 320);// Set size , visualization , sign out setVisible(true); Dimension faceSize = new
Dimension(550, 320); Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((int)
(screenSize.width - faceSize.getWidth()) / 2, (int) (screenSize.height -
faceSize.getHeight()) / 2); // sign out exit.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) { dispose(); } });
this.addWindowListener(new WindowAdapter() { @Override public void
windowClosing(WindowEvent e) { dispose(); } }); } // Query refresh box of header private void
toppanel() { panel1=new Panel(); sid1 = new Label(" Student number :"); sid11 = new
TextField(15); look = new Button(" query "); refresh = new Button(" Refresh "); exit = new
Button(" sign out "); panel1.setVisible(true); add(panel1, "North");
panel1.add(sid1);// Add to panel1 panel1.add(sid11); panel1.add(look);
panel1.add(refresh); panel1.add(refresh); panel1.add(exit);
look.addActionListener(this); refresh.addActionListener(this); } // Three function box
private void mainpanel() { panel0=new Panel(); delete1 = new Button(" delete ");
submit1= new Button(" add to "); reset1 = new Button(" modify "); panel0.add(submit1);
panel0.add(delete1); panel0.add(reset1); panel0.setVisible(true); add(panel0,
"South"); delete1.addActionListener(new ActionListener() { // delete frame public void
actionPerformed(ActionEvent e) { panel4(); } }); submit1.addActionListener(new
ActionListener() { // increase frame public void actionPerformed(ActionEvent e) {
panel3(); } }); reset1.addActionListener(new ActionListener() { // Delete modify box public
void actionPerformed(ActionEvent e) { panel2(); } }); setVisible(true); } // Modify box
private void panel2() { table(DBHelper.query("select * from studentgrade order
by sid ")); // Initial panel display information remove(panel0); panel2 = new Panel(); // set up Input box
panel2.setLayout(new GridLayout(4,3)); sid2 = new Label(" Student number "); subject1 = new
Label(" subject "); studentgrade1 = new Label(" achievement "); empty = new Label(""); empty1=new
Label(""); empty2=new Label(""); reset = new Button(" modify "); back=new
Button(" return "); sid22 = new TextField(); subject2 = new TextField();
studentgrade2 = new TextField(); panel2.add(sid2); panel2.add(sid22);
panel2.add(empty); panel2.add(subject1); panel2.add(subject2);
panel2.add(empty1); panel2.add(studentgrade1); panel2.add(studentgrade2);
panel2.add(empty2); panel2.add(reset); panel2.add(back);
reset.addActionListener(this); panel2.setVisible(true); add(panel2, "South");
back.addActionListener(new ActionListener() { // Return to select function interface public void
actionPerformed(ActionEvent e) { table(DBHelper.query("select * from
studentgrade order by sid ")); // Initial panel display information remove(panel2); mainpanel(); } });
setVisible(true); } // Add box private void panel3() { table(DBHelper.query("select
* from studentgrade order by sid ")); // Initial panel display information remove(panel0); panel3 = new
Panel(); // set up Input box panel3.setLayout(new GridLayout(5,3)); sid2 = new
Label(" Student number "); subject1 = new Label(" subject "); studentgrade1 = new Label(" achievement ");
empty = new Label(""); empty1=new Label(""); empty2=new Label(""); empty3=new
Label(""); classcode=new Label(" Teaching class "); submit = new Button(" add to "); back=new
Button(" return "); sid22 = new TextField(); subject2 = new TextField();
classcode1=new TextField(); studentgrade2 = new TextField(); panel3.add(sid2);
panel3.add(sid22); panel3.add(empty); panel3.add(subject1);
panel3.add(subject2); panel3.add(empty1); panel3.add(studentgrade1);
panel3.add(studentgrade2); panel3.add(empty2); panel3.add(classcode);
panel3.add(classcode1); panel3.add(empty3); panel3.add(submit);
panel3.add(back); submit.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) { String s4=null,s5=null; String
s1=sid11.getText(); String s2 =sid22.getText(); String subject=
subject2.getText();// bottom // jdbc Data addition // name2, subject2, studentgrade2,
classcode2, adminiclass2; if (sid22.getText().length() ==
0||subject2.getText().length()==0||studentgrade2.getText().length()==0||classcode1.getText().length()==0
){ JOptionPane.showMessageDialog(null, " Please input all information correctly !"); } else { try {
rs=DBHelper.query("select name,adminiclass from studentinfo where sid="+s2);
while (rs.next()) { s4=rs.getString("name"); s5=rs.getString("adminiclass"); }
String s6=null; String s7=null; rs=DBHelper.query("select* from studentgrade
where sid="+s2); while (rs.next()) { s6=rs.getString("classcode");
s7=rs.getString("subject"); } if(s6!=null||s7!=null){
JOptionPane.showMessageDialog(null, " A grade already exists in this subject !"); }else{ // Defining data String
studentgrade = studentgrade2.getText(); String classcode=classcode1.getText();
String sql = "insert into
studentgrade(sid,name,adminiclass,classcode,subject,studentgrade)
value("+s2+",'"+s4+"','"+s5+"','"+classcode+"','"+subject+"','"+studentgrade+"')";
DBHelper.update(sql); JOptionPane.showMessageDialog(null, " Data added successfully !"); } } catch
(Exception e11) { e11.printStackTrace(); } sid22.setText("");
subject2.setText(""); // After adding successfully Reset information input box studentgrade2.setText("");
classcode1.setText(""); } table(DBHelper.query("select * from studentgrade
order by sid ")); // Initial panel display information } }); back.addActionListener(this);
panel3.setVisible(true); add(panel3, "South"); back.addActionListener(new
ActionListener() { // Return to select function interface public void actionPerformed(ActionEvent e) {
table(DBHelper.query("select * from studentgrade order by sid ")); // Initial panel display information
remove(panel3); mainpanel(); } }); setVisible(true); } // Delete box private void
panel4() { table(DBHelper.query("select * from studentgrade order by sid "));
// Initial panel display information remove(panel0); panel4 = new Panel(); // set up Input box
panel4.setLayout(new GridLayout(3,3)); sid2 = new Label(" Student number "); subject1 = new
Label(" subject "); empty = new Label(""); empty1=new Label(""); delete=new
Button(" delete "); reset = new Button(" modify "); back=new Button(" return "); sid22 = new
TextField(); subject2 = new TextField(); panel4.add(sid2); panel4.add(sid22);
panel4.add(empty); panel4.add(subject1); panel4.add(subject2);
panel4.add(empty1); panel4.add(delete); panel4.add(back);
delete.addActionListener(this); back.addActionListener(this);
panel4.setVisible(true); add(panel4, "South"); back.addActionListener(new
ActionListener() { // Return to select function interface public void actionPerformed(ActionEvent e) {
table(DBHelper.query("select * from studentgrade order by sid ")); // Initial panel display information
remove(panel4); mainpanel(); } }); setVisible(true); } // Collection of button events public void
actionPerformed(ActionEvent e) { Object obj = e.getSource(); String
s4=null,s5=null; String s1=sid11.getText(); if (obj == look) { try { //
Inquiry student number is "s1" My students rs = DBHelper.query("select * from studentgrade where sid='" + s1
+ "'"); int sid1 = 0; while (rs.next()) { String sa = rs.getString("sid"); if
(s1 != sa) { sid1 = 1; break; } } if (sid1== 0) { if (sid11.getText().length()
== 0) { // When the query box is empty Tips JOptionPane.showMessageDialog(null, " All student information will be queried ");
table(DBHelper.query("select * from studentgrade order by sid ")); } else {
JOptionPane // When the input student number does not exist .showMessageDialog(null, " Cannot find student number " + s1 + " Student information for "); } }
else { rs = DBHelper .query("select * from studentgrade where sid='" + s1 +
"'"); table(rs); } } catch (SQLException e1) { // TODO Automatically generated catch block
e1.printStackTrace(); } } else if (obj == delete) { String s2 =sid22.getText();
String subject= subject2.getText();// bottom String sidd ; try { rs =
DBHelper.query("select * from studentgrade where sid='" +s2+ "'"); int sid1=0;
int sub1=0; while (rs.next()) { sidd=rs.getString("sid"); if (s2.equals( sidd))
{ sid1 = 1; break;// There is a student number } } DBHelper.close(); rs = DBHelper.query("select *
from studentgrade where sid='" +s2+ "'"); while (rs.next()) { String
subb=rs.getString("subject"); if(subject.equals(subb)){ //subject It's the subject of your own input box
sub1=1; break; } } if (sid22.getText().length() ==
0||subject2.getText().length()==0) { // When the query box is empty Tips
JOptionPane.showMessageDialog(null, " Please input student number and subject "); } else if (sid1== 0) {
JOptionPane.showMessageDialog(null, " Cannot find student number " + s2 // + " Student information for "); } else
if(sub1==0){ JOptionPane.showMessageDialog(null, " The account was not found " ); } else { String
sql =" delete from studentgrade where subject='"+subject+"' and sid='"+s2+"'" ;
DBHelper.update(sql); JOptionPane .showMessageDialog(null, " You deleted the student number of " + s2 +
", Subject is "+subject+" Achievements "); // } } catch (Exception e2) { // TODO: handle exception
} table(DBHelper.query("select * from studentgrade order by sid ")); //
Initial panel display information sid22.setText(""); subject2.setText(""); } else if (obj == reset) {
String s2 =sid22.getText(); String subject= subject2.getText();// bottom try { rs =
DBHelper.query("select * from studentgrade where sid='" +s2+ "'"); int sid1=0;
int sub1=0; while (rs.next()) { String sidd =rs.getString("sid"); if
(s2.equals( sidd)) { sid1 = 1; break;// There is a student number } } DBHelper.close(); rs =
DBHelper.query("select * from studentgrade where sid='" +s2+ "'"); while
(rs.next()) { String subb=rs.getString("subject"); if(subject.equals(subb)){
//subject It's the subject of your own input box sub1=1; // existence break; } } if (sid22.getText().length() ==
0||subject2.getText().length()==0||studentgrade2.getText().length()==0) { //
When the query box is empty Tips JOptionPane.showMessageDialog(null, " Please input all information correctly "); } else if (sid1 ==
0) { JOptionPane.showMessageDialog(null, " Cannot find student number " + s2 // + " Student information for "); } else if
(sub1==0 ) { JOptionPane.showMessageDialog(null, " The account was not found "); }else{ String
studentgrade = studentgrade2.getText(); String sql = "update studentgrade set
studentgrade='"+studentgrade +"'where sid=" + s2+" and subject='"+subject+"' ";
DBHelper.update(sql); JOptionPane .showMessageDialog(null, " Modified successfully !"); rs =
DBHelper.query("select * from studentgrade where sid='"+s2+ "'"); } }catch
(Exception e1) { // TODO: handle exception } sid22.setText("");
subject2.setText(""); studentgrade2.setText(""); table(DBHelper.query("select *
from studentgrade order by sid ")); // Initial panel display information } else if (obj == refresh) {
table(DBHelper.query("select * from studentgrade order by sid ")); setSize(450,
320);// Set size , visualization , sign out setVisible(true); } } private void table(ResultSet rs) { //
TODO Automatically generated method stub String[] cowname = { " Student number ", " name ", " Administration class ", " Teaching class ", " subject ", " achievement ", };
if (model != null || jTable1 != null) remove(check); model = new
DefaultTableModel(); model.setColumnIdentifiers(cowname); try { while
(rs.next()) { Vector<String> data = new Vector<String>();
data.add(rs.getString("sid")); data.add(rs.getString("name"));
data.add(rs.getString("adminiclass")); data.add(rs.getString("classcode"));
data.add(rs.getString("subject")); data.add(rs.getString("studentgrade"));
model.addRow(data); } } catch (SQLException e1) { // TODO Auto-generated catch
block e1.printStackTrace(); } // Set information box jTable1 = new JTable(model);
jTable1.setEnabled(false); check = new JScrollPane(jTable1); add(check,
"Center"); setVisible(true); } /* public static void main(String[] args) {
GradeChange Gender = new GradeChange(); }*/ }
<> Partial screenshot

Main panel
The background is the characteristic of our school , Chinese soft silk kapok
Student number will be determined according to admission time , Department major , Automatic generation of administrative class
Click the different buttons below , The corresponding box will pop up

Technology