Package Bookdemo_1;import javax.swing.*;import java.awt.*;import java.awt.event.*;p ublic class Test {public static voi D main (string[] args) {Studentsys stusys=new Studentsys ("Student management System"); Stusys.initwin (); }}class Studentsys extends Jframe{private JPanel p1,p2,p3,combop;private JTabbedPane tab;private Container CONTAINER;PR Ivate JButton b1,b2;private Listener listener;private label namelabel;private label Gradelabel;private label ShowLabel; Private JTextField textname;private JTextField textgrade;private TextArea showgradearea;/** Find * */private Label Searchlabel;private JTextField searchtext;private JButton sbut;private jtextfield resulttext;private String[] name; Private string[] grade;/** sort * */private TextArea showtextarea;private JButton sortbut;private int countnum=0;private JBu Tton clearbut;public Studentsys (String str) {super (str); this.name=new string[100];this.grade=new string[100]; Listener = new Listener (); tab = new JTabbedPane (jtabbedpane.top); Container container = This.getlayerEdpane ();//object panel Combop = new JPanel ();p 1 = new JPanel ();p 2 = new JPanel ();p 3 = new JPanel (); B1 =new JButton ("confirm Add"); B2 =ne W JButton ("Recall add"), Namelabel =new label ("name"), Gradelabel =new label ("Score"); showlabel=new label ("The current record is zero!") "); Textname =new JTextField (); Textgrade =new JTextField (); showgradearea=new TextArea ();/** search * */searchlabel=new Label ("Please enter Name:"); searchtext=new JTextField (sbut=new) JButton ("Confirm Lookup"); resulttext=new JTextField (15);/** Sort * * * Showtextarea=new TextArea (); Sortbut=new JButton ("score sort"); Clearbut=new JButton ("emptying data");} public void Initwin () {this.setbounds (a), This.addwindowlistener (new Windowadapter () {public void Windowclosing (WindowEvent e) {super.windowclosing (e); System.exit (0);}); Layoutwin (); this.setvisible (true);} private void Layoutwin () {Tab.add (P1, "score input"), Tab.add (P2, "score query"), Tab.add (P3, "score sort"), Combop.add ("Student Information Management system"); "); Container.setlayout (new BorderLayout ()); Container.add (Combop,borderlayout.north); Container.add (Tab,BoRderlayout.center); Container con1=new Container () con1.setlayout (New FlowLayout ()); Con1.add (Namelabel); Con1.add (textname); Con1.add ( Gradelabel) Con1.add (textgrade);p 1.add (Con1,borderlayout.north);p 1.add (con1);p 1.add (Showgradearea); Container con2=new Container (); Con2.setlayout (new FlowLayout ()); Con2.add (B1); Con2.add (B2); Con2.add (ShowLabel); P1.add (Con2); B1.addactionlistener (listener); B2.addactionlistener (listener);/** Find layout * */container con3=new Container (); Con3.setlayout (new FlowLayout ()); Con3.add (Searchlabel); Con3.add (SearchText); Con3.add (sbut);p 2.add ( Con3,borderlayout.north); Sbut.addactionlistener (listener);p 2.add (resulttext);/** Sort layout * */p3.add (Showtextarea); P3.add (sortbut);p 3.add (clearbut); Sortbut.addactionlistener (listener); Clearbut.addactionlistener (listener);} /** Java internal class implementation ActionListener interface * */class Listener implements actionlistener{@Overridepublic void actionperformed ( ActionEvent e) {if (E.getsource () ==b1) {if (Textname.gettext (). Equals ("")) | | (Textgrade.gettext (). Equals (""))) {ShowlabeL.settext ("Add failed (name, score cannot be empty)!" ");} Else{name[countnum]=textname.gettext (); Grade[countnum]=textgrade.gettext (); countnum++; String area= "added successfully, currently has" +countnum+ "record"; Showlabel.settext (area); sortmess (false); Textname.settext (""); Textgrade.settext ("");}} if (E.getsource () ==b2) {if (countnum>0) {countnum--; String Area= "Recall succeeded, currently has" +countnum+ "record"; Showlabel.settext (area); sortmess (false);}} if (E.getsource () ==sbut) {if (!searchtext.gettext (). Equals ("")) {searchmess (Searchtext.gettext ());}} if (E.getsource () ==sortbut) {sortmess (true);} if (E.getsource () ==clearbut) {if (!showtextarea.gettext (). Equals ("")) {Showtextarea.settext ("");}}} public void Sortmess (Boolean sign) {//TODO auto-generated method stubif (sign) {for (int. i=0;i<countnum;i++) {for (int j= i+1;j<countnum;j++) {if (Integer.parseint (Grade[i]) <integer.parseint (Grade[j])) {String s1,s2;s1=name[i];s2= Grade[i];name[i]=name[j];grade[i]=grade[j];name[j]=s1;grade[j]=s2;}}}} else{if (!showgradearea.gettext (). Equals ("")) {Showgradearea.settext ("");}} for (int I=0;i<countnum;i++) {String content= "name:" +name[i]+ "\ T" + "score" +grade[i];if (sign) showtextarea.append (content+ "\ n"); else Showgradearea.append (content+ "\ n");}} public void searchmess (String n) {//TODO auto-generated method stubfor (int i=0;i<countnum;i++) {if (Name[i].equals (n) {String content= "name:" +name[i]+ "," + "score" +grade[i];resulttext.settext (content); return;}} Resulttext.settext ("The student was not found!");}}
Java Version Student Management system