Student score management system written by Java

xiaoxiao2021-03-17  212

Import java.applet.applet; import java.awt. *; import java.awt.event. *; import java.util. *; import java.lang. *;

Public class students an actionListener {Vector stuinf = new vector (); studentinf Si; string xm; string bj; int i, j, xh, cj; static int mid; label prompt1 = new label ("Student Results Management System" Label Prompt2 = New Label ("User:"); Label Prompt3 = New Label ("Password:"); Label Prompt4 = New Label ("Class:"); Label Prompt5 = New Label ("Score:"); TextField input1 = new TextField (8); TextField input2 = new TextField (8); TextField input3 = new TextField (8); TextField input4 = new TextField (8); Button btn1 = new Button ( "Login"); Button btn2 = New Button; Button BTN3 = New Button; Button BTN4 = New Button ("Delete"; Public Void Init () {setLayout (NEW GridLayout (6, 3)); add (new Label ()); add (new label ()); add (pROMPT2); add (infut1); add (new label ()); add (prompt3); add (input2); add (btn1) Add (pROMPT4); Add (new label ()); add (pROMPT5); add (input4); add (new label ()); add (btn2); add (btn3); add (btn4 PROMPT4.SETVISIBLE (FALSE); Prompt5.SetVisible (false); Input3.SetVisible (False); INPUT4.SETVISIBLE (FALSE); btn2.setvisible (false); btn3.setVisible (false); btn4.setVisible (false); btn1.addactionListener (this); btn2.addactionListener (this); btn3.addActionListener This); btn4.addactionListener (this);} public void actionPerformed (ActionEvent E) {if (E.GetActionCommand () == "Login" {String A, B; A = INPUT1.GETTEXT (); b = INPUT2. GetText (); INPUT1.SETTEXT (""); IF ((A.Equals) == True && (B.Equals ("12") == true)) {prompt2.settext ("Name: "); Prompt3.Settext (" Learn: ");

Prompt4.setVisible (TRUE); INPUT3.SETVISIBLE (TRUE); Input4.SetVisible (TRUE); btn2.setVisible (TRUE); btn3.setVisible (TRUE); btn4.setVisible; btn3 .setenabled (false); btn4.senabled (false); btn1.setLabel ("Query"); INPUT1.SETTEXT ("Login Success"); input1.selectall ();} else input2.settext ("username or password ");}} G (E.GetActionCommand () ==" Add ") {boolean scuCss = true; try {xingming ();} catch (emptyexception as) {input1.settext (" Name cannot be empty "); scuCss = False;} try {xh = integer.parseint ());} catCH (NumberFormatexception M) {INPUT2.SETTEXT ("Learn is empty or formatted"; scuCss = false;} bj = input3.gettext (); Try {Chengji (); Catch (EmptyException as) {CA = -1;} catch (Overexception DD) {INPUT4.SETTEXT ("should be in 0-100"); scuCSS = false;} catch (NumberFormatexception) CM) {INPUT4.SETTEXT ("score should be data"); scuCSS = false;} f (scuCss == true) {si = new studentInf (xm, xh, bj, cj); INSERT (SI);}} if (E.GetActionCommand () == "Modified") {xm = INPUT1.GETTEXT (); xh = integer.parseint (Input2.getText ()); bj = input3.getText (); CJ = INTEGER.PARSEINT (INPUT4.GETTEXT ()); Si = New StudentInf (XM, XH, BJ, CJ); StuInf.Stelementat (Si, MID); btn3.setenabled (false);} if (E.GetActionCommand ) == "Delete") {stuinf.removeElementat (MID); btn4.setenabled (false); input1.settext ("Delete Success"); input2.setText (""); input3.setText (""); Input4. Settext ("");} if (E.GetActionCommand () == "query" {boolean right = true;

Try {xh = integer.parseint (INPUT2.GETTEXT ());} catch (Numberformatexception M) {INPUT2.SETTEXT ("Learn is empty or formatted"); Right = false;} if (right == true) { Search (XH); btn3.setenabled (True); btn4.setenabled (true);}}} // Find method public void search (int K) {boolean exist = false; int low = 0; int high = stuinf.size () -1; while (low <= high) {mid = (high low) / 2; studentinf a1 = (studentInf) stuinf.ementatat (mid); if (a1.getstuno () == k) {si = (StudentInf); String x = string.valueof (Si.GetStuno ()); exist = true; input1.settext (si.getname ()); input1.selectall (); input2.setText (" 0 " x); Input3.Settext (Si.getClassno ()); if (Si.getLevel () == - 1) Input4.Settext (" Do not participate in the test "); else {string y = string.valueof (Si) .get4.Settext (y);} Break;} else if (a1.getstuno ()

INPUT2.SELECTALL (); else {stuinf.insertelementat (q, i); input1.settext (""); input2.setText (""); input3.setText (""); input4.setText (""); }}} // exception class class OverException extends exception {String over;} class EmptyException extends exception {String empty;} void XingMing () throws EmptyException {if (. (input1.getText ()) equals ( "")) throw ( New emptyException (); else xm = INPUT1.GETTEXT ();} void Chengji () THROWS OVEREXCEPTION, EMPTYEXCEPTION {IF ((INPUT4.GETTEXT ()). Equals (")) throw (new EmptyException ()); else CJ = INTEGER.PARSEINT (INPUT4.GETTEXT ()); if (CJ <0 || CJ> 100) THROW (New Overexception ());} // Student Information Class PUBLIC CLASS StudentInf {Private String Name; Private Int Stuno; private String classNo; private int Level; StudentInf (String xingming, int xuehao, String banji, int chengji) {name = xingming; stuNo = xuehao; classNo = banji; Level = chengji;} public int getStuNo () {return stuNo;} Public string getname () {return name;} Public string getclassno () {return classno;} public int getLesno;}}}}

转载请注明原文地址:https://www.9cbs.com/read-129578.html

New Post(0)