A job in school primary school, using files to achieve access to data, if the database may be simple, but the system is small, so the difference is not very big. Send it to everyone criticized criticism. . .
Description:
This program also needs to build a StudentInfo folder in the program current folder, where you put a StudentInfo.txt file format as follows:
Name ID SEX S1 S2 S3 S4 S5XXX 02281301 Male 88 87 90 82 89YYY 02281302 Male 85 94 86 87 89ZZZ 02281303 Male 84 86 81 82 81
Also build an image folder, put some student avatar, but if you don't want to achieve this, you can don't put it.
Source code:
Managegui.java
Package scoremanage;
import java.util *;. import java.awt *;. import java.awt.event *;. import javax.swing *;. import javax.swing.DefaultListModel; import javax.swing.table.DefaultTableModel; import javax.swing .
/ ** This class provides a interactive interface to users * / public class ManageGUI {ScoreControl ScrCtrl; JFrame mainF; JPanel mainP; JMenuBar mainMB; JMenu fileM, manageM, helpM; JMenuItem stuinfoMI, saveMI, quitMI, queryMI, insertMI, deleteMI, searchMI , infoMI; // JTable DefaultTableModel TModel; JTable InfoTable; Object [] [] InfoCell; String [] ColumnName; // JList final String PATH = "Image /"; DefaultListModel LModel; JList sList; JLabel sImage; JTextArea stuinfoTA; ImageIcon img ; JSplitPane innerPane; JSplitPane outerPane; // query JPanel queryP; JTextField queryTF; ButtonGroup queryBG; JRadioButton first, second, third; JTextArea queryTA; ArrayList QStuInfo = new ArrayList (); public ManageGUI () {// creates a aggregative object to operate the SInfo ScrCtrl = new ScoreControl (); mainF = new JFrame (); mainF.addWindowListener (new WindowAdapter () {public void windowClosing (WindowEvent e) {quitDlg ();}}); mainP = new JPanel (); mainP. Add (New Jlabel ("STUDEN TS 'Information Report "); addComponent (); showframe (); system.gc ();} public void addmenu () {mainmb = new jmenubar (); filem = new jmenu (" file "); Managem = new jmenu ("manage"); helpM = new jmenu ("help"); mainf.setjmenubar (mainmb); mainmb.add (filem); mainmb.add (helpM); stuinfomi = NEW JMENUITEM ("stuinfo"); stuinfomi.addActionListener (new mlistener ()); filem.add (stuinfomi); Savemi = new jmenuitem ("save"); Savemi.AddActionListener (new mlistener ()); filem.add (Savemi ); Quitmi = new jmenuitem ("quit"); quitmi.addActionListener (new mlistener ());
fileM.add (quitMI); queryMI = new JMenuItem ( "Query"); queryMI.addActionListener (new MListener ()); manageM.add (queryMI); insertMI = new JMenuItem ( "Insert"); insertMI.addActionListener (new MListener ()); Managem.add (insertmi); deletemi = new jmenuitem ("delete"); deletemi.addactionListener (new mlistener ()); managementm.add (deletemi); searchmi = new jMenuItem ("Search"; Searchmi. addActionListener (new MListener ()); manageM.add (searchMI); infoMI = new JMenuItem ( "Info"); infoMI.addActionListener (new MListener ()); helpM.add (infoMI);} public void addComponent () {createStuInfoTable (); Createstuinfolist (); public void showframe () {mainf.settitle ("scoremanage"); mainf.setsize (650, 550); mainf.setlocation (200, 100); mainf.setvisible (TRUE);}
Public void createstuinfotable () {infocell = new object [scrCtrl.stulist.size ()] [scrute.snamelist.size ()]; int J = 0; for (int i = 0; i i ) LModel.addElement (ScrCtrl.StuList.get (i)); sList = new JList (LModel); sImage = new JLabel (); stuinfoTA = new JTextArea (4,10); innerPane = new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, new JScrollPane (sList), sImage); innerPane.setBackground (Color.WHITE); innerPane.setContinuousLayout (true); innerPane.setOneTouchExpandable (true); outerPane = new JSplitPane (JSplitPane.VERTICAL_SPLIT, innerPane, new JScrollPane (stuinfoTA)); sList.addListSelectionListener (new ListSelectionListener () {public void valueChanged (ListSelectionEvent event) {StudentInfo value = (StudentInfo) sList.getSelectedValue ();! if (value = null) {int index = (int) (Math.random () * 10); img = new imageicon (path index ".gif"); Simage.seticon; Stuinfota.Settext ("Student Record:" "/ N" value.getname () "/ n" VA Lue.getnum () "/ n" value.getSex ());}}});} Class Mlistener Implements ActionListener {Public Void ActionPerformed (ActionEvent E) {Object Command = E.GetSource (); IF (Command == StuInfomi) {stuinfodlg ();} else if (Command == Savemi) {WriteFiledlg ();} else if (command == quitmi) {quitdlg ();} else if (command == querymi) { Else IF ()} else} else} else} else} else} else} else} else}} else}} else} else} else} else} else} else} else} else} else} else} else} else}} else}} else}} else}}} else}} else}} else}} else}} else}} else}} else} {SearchDLG ();} else command == infoMI) {infoDlg ();}}} public void stuInfoDlg () {JOptionPane.showConfirmDialog (null, outerPane, "Student Info", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);} public void writeFileDlg () {ScrCtrl. Writefile (); jPanel msgp = new jPanel (); msgp.add (New Jlabel ("Your File Is Saved In The Current Dir"); JOPTITIONPANE.SHOWMESSAGEDIALOG (Null, Msgp, "Save", JOptionpane.yes_option;} Public void quitdlg () {jPanel msgp = new jPanel (); msgp.add (New Jlabel ("SAVE FILE?")); if (JOPANE.SHOWCONFIRMDIALOG (NULL, MSGP, "Save", JOptionpane.ok_cancel_option, joption PANE.PLAIN_MESSAGE) == JOPTIONPANE.OK_OPTION) {scrCtrl.writefile ();} system.exit (0); // query begin public void querydlg () {queryp = new jPanel (); queryTf = new jtextfield (8); jPanel infop = new jPanel (); infop.add ("Subject"); infop.add QueryTF); querybg = new button set (); first = new jradiobutton ("0 <= score <60"); first.addactionListener (new rblistener ()); querybg.add (first); second = new jradiobutton ("60 < = Score <90 "); second.addactionListener (new rblistener ()); querybg.add (second); third = new jradiobutton (" 90 <= score <100 "); third.addactionListener (new rblistener ()); querybg .add (third); JPANEL BTNP = new jPanel (); btnp.add (first); btnp.add (second); queryp.add (info); queryp.add (btnp); queryta = new JTextArea (10,30); queryTA.setEditable (false); JSplitPane querySP = new JSplitPane (JSplitPane.VERTICAL_SPLIT, queryP, new JScrollPane (queryTA));; JOptionPane.showConfirmDialog (null, querySP, "Query", JOptionPane. OK_CANCEL_OPTION, JOPTIONPANE.PLAIN_MESSAGE);} public void se LectQuery (int flag) {string subject = queryTf.getText (). Trim (); int belou = 0, high = 0; // clear the contents of the queryta queryta.setText (""); switch (flag) {casse 1: Below = 0; high = 60; Break; case 2: Below = 60; high = 90; break; case 3: Below = 90; high = 100; break; default: Break;} // select the sujectiff Subject.equals (sprctrl.snamelist.get (3))) {for (int i = 0; i Integer.Parseint ((studentInfo) Scrctrl.stulist.get (i)). GetScore1 ()) ");}} Public void displayQuery () {if (qstuinfo.size () == 0) {queryta.settext (" no match item is all ");} else {for (int i = 0 i new JTextField (6); JTextField score3TF = new JTextField (6); JTextField score4TF = new JTextField (6); JTextField score5TF = new JTextField (6); insertP.setLayout (new GridLayout (4,4)); insertP.add ( New Jlabel ("name"); INSERTP.ADD (Nametf); INSERTP.ADD (New Jlabel ("ID")); INSERTP.ADD (NumTf); INSERTP.ADD (New Jlabel ("SEX"); Insertp .add (sextf); INSERTP.ADD (New Jlabel ("score1")); INSERTP.ADD (Score1TF); INSERTP.ADD (New Jlabel ("score2")); INSERTP.ADD (Score2TF); INSERTP.ADD ( NEW JLABEL ("score3"); INSERTP.ADD (score3TF); INSERTP.ADD (New Jlabel ("score4")); INSERTP.ADD (Score4TF); INSERTP.ADD (New Jlabel ("score5"); insertp .add (score5TF); if (JOptionPane.showConfirmDialog (null, insertP, "Insert", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {String name = nameTF.getText () trim ();. String num = NumTf.getText (). Trim (); string sex = sextf.gettext (). Trim (); string score1 = score1tf.gettext (). Trim (); string score2 = score2tf.gettt EXT (). Trim (); string score3 = score3tf.gettext (). Trim (); string score4 = score4tf.getText (). Trim (); string score5 = score5tf.getText (). Trim (); if (((); if ! Name.Equals (")) && (! num.equals (")) && (! SEX.EQUALS (")) && (! score1.equals (")) && (! score2.equals " ")) && (! score3.equals (")) && (! score4.equals (")) && (! score5.equals ("))) {for (int i = 0; i ) {IF (Num.Equals ((studentInfo) Scrctrl.stulist.get (i)). Getnum ())) {jPanel msgp = new jPanel (); msgp.add (New Jlabel ("The Record EXIST")) ; JOptionPane.showMessageDialog (null, msgP, "Message", JOptionPane.YES_OPTION); return;}} String totalscore = String.valueOf (Integer.parseInt (score1) Integer.parseInt (score2) Integer.parseInt (score3) Integer.parseInt (score4) Integer.parseInt (score5)); String averagescore = String.valueOf (Integer.parseInt (totalscore) / 5); StudentInfo SInfo = new StudentInfo (name, num, sex, score1, score2, score3, Score4, Score5, Totalscore, AverageAgeScore; Scrctrl.stulist.Add (SINFO); Scrctrl.Sortstuinfo (); //scrctrl.writefile (); string [] Rowcell = {Name, Num, SEX, Score1, Score2, Score3, Score4, Score5, Totalscore, Average JTable TMODEL.Addrow (Rowcell); // Change Jlist LMODEL.Addelement (SINFO); System.out.println (Scrctrl.Stulist.size ());} else {jPanel msgp = new jPanel (); msgp.add ("You Should Fill Blanks")); JOPTIONPANE.SHOWMESAGEDIALOG (NULL, MSGP , "Message", JOPANE.YES_OPTION;}}}}}}}}}}} {jPanel DELP = New jPanel (); jtextfield deltf = new jtextfield (8); Delp.Add ("ID") ); delP.add (delTF); if (JOptionPane.showConfirmDialog (null, delP, "Delete", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {String num = delTF.getText () trim (). For (int i = 0; I ) {IF (Num.Equals ((studentInfo) Scrctrl.stulist.get (i)). Getnum ())) {Vector sinfo = new vector (); studentInfo temp = (studentInfo) Scrctrl.stulist.get (i) Sinfo.add (Temp.getName ()); sinfo.add (Temp.Getnum ()); sinfo.add ()); sinfo.add (Temp.getscore1 ()); sinfo.add (Temp .getscore2 ()); sinfo.add (temp.getscore3 ()); sinfo.add (Temp.getscore4 ()); sinfo.add (Temp.getscore5 ()); sinfo.add (Temp.gettotalscore); SINFO.ADD (Temp.GetaveRageScore ()); System.out.Println (SINFO); for (int J = 0; j Msgp.add (New Jlabel (Temp.getname () "" TEMP.GETSEX () "" TEMP.GETSCORE1 () "" TEMP.GETSCORE2 () " " TEMP.GETSCORE3 () " " " TEMP.GETSCORE5 () " TEMP.GETTOTAVERSCORE () " TEMP.GETAVERAGESCORE ())); JOPTIONPANE.SHOWMESSAGEDIALOG ( NULL, MSGP, "Message", JOPTIONPANE.YES_OPTION; RETURN;}} jPanel msgp = new jPanel (); msgp.add ("The Record Does Not Exist"); JOPTIONPANE.SHOWMESSAGEDIALOG (NULL, MSGP, "Message", joptionpane.yes_option;} // demo info public void infodlg () {jPanel msgp = new jPanel (); msgp.setLayout (new gridLayout (4, 1)); msgp.add ("new jlabel (" "); Msgp.add (New Jlabel (" Author: Pluto ")); Msgp.Add (New Jlabel (" Date: 2005.1 ")); Msgp.Add (New Jlabel (" Site: bjtu 15 # ")); JOPTIONPANE.SHOWMESSAGEDIALOG (NULL, MSGP," INFO ", JOPTIONPANE.YES_OPTION; public static void main (string [] args) {new Managegui ();}} studentinfo.java Package scoremanage; / ** This class encapsulates the informations of students * / class StudentInfo {// static info String name, num, sex; // score info String score1, score2, score3, score4, score5, totalscore, averagescore; public StudentInfo (String name, String num , String sex, String score1, String score2, String score3, String score4, String score5, String totalscore, String averagescore) {this.name = name; this.num = num; this.sex = sex; this.score1 = score1; this.score2 = score2; this.score3 = score3; this.score4 = score4; this.score5 = score5; this.totalscore = totalscore; this.averagescore = averagescore;} public String getName () {return name;} public String getNum () {return num;} public String getSex () {return sex;} public String getScore1 () {return score1;} public String getScore2 () {return score2;} public String getScore3 () {return score3;} public String getScore4 () {Return score4;} public string getscore5 () {returnis score5;} public stri ng getTotalScore () {return totalscore;} public String getAverageScore () {return averagescore;} // The default stuinfoTA of the object public String toString () {return name;}} ScoreControl.java Package scoremanage; Import java.io. *; import java.util. *; / ** This class is the main class thing interacts with other classes * / Public class ScoreControl {public ArrayList SNameList = new ArrayList (); public ArrayList StuList = new ArrayList (); public ScoreControl () {ReadFile (); SortStuInfo (); // WriteFile ();} public void ReadFile () { File stuf = null; FileInputStream fis = null; BufferedReader br = null; StudentInfo SInfo; String stu, name, num, sex; String score1, score2, score3, score4, score5, totalscore, averagescore; StringTokenizer temp; stuf = new File ( "Student Info / StudentInfo.txt"); try {fis = new FileInputStream (stuf);} catch (Exception efis) {System.out.println ( "FileInputStream Error"); efis.printStackTrace ();} br = new BufferedReader (New INPUTSTREAMREADER (FIT {// read the subjects name from the file stu = br.readline (); temp = new StringTokenizer (STU); while (Temp.hasmoreToKens ()) {SnameList.Add (Temp. NEXTTOKEN ());} snamelist.add ("total"); snamelist.add ("average"); // read the students' Infos from the file while (true) { IF ((stu = br.readline ()) == null) {Break;} else {temp = new StringTokenizer (STU); // static infos name = temp.nextToken (); Num = Temp.nextToken (); SEX = Temp.nextToken (); // score infos score1 = Temp.nextToken (); score2 = temp.nextToken (); score3 = temp.nextToken (); score4 = temp.nextToken (); score5 = temp.nextToken () Totalscore = String.Valueof (Integer.Parseint (Score1) Integer.Parseint (Score2) Integer.Parseint (score4) Integer.Parseint (score5)); AVERAGESCORE = String.valueOf (Integer.parseInt (totalscore) / 5); // create StudentInfo objects and put them in the SInfo array SInfo = new StudentInfo (name, num, sex, score1, score2, score3, score4, score5, totalscore, averagescore ); Stulist.add (sinfo);}} // close the current fis.close (); br.close ();} catch (Exception EBR) {system.out.println ("BufferedReader Error"); ebr.printStackTrace ();}} // sort the students by the total score public void Sortstuinfo () {Object TempsInfo; for (int i = 0; i