/** * @author Li Pei * * @version v1 * * @time 2016/12/6 9:29 * * @program draw Student Interface for Students ' Course selection system * */package Com.csms.windows;impor T Java.awt.borderlayout;import java.awt.dimension;import Java.awt.font;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Java.util.arraylist;import Java.util.list;import Javax.swing.Icon;import Javax.swing.imageicon;import Javax.swing.jbutton;import Javax.swing.jframe;import Javax.swing.JPanel;import Javax.swing.jpasswordfield;import Javax.swing.jscrollpane;import Javax.swing.jtable;import Javax.swing.JTextField ; Import Javax.swing.table.abstracttablemodel;import Javax.swing.table.defaulttablemodel;import Com.csms.dao.coursedao;import Com.csms.dao.selectcoursedao;import Com.csms.dao.teacherdao;import Com.csms.entity.course;import Com.csms.entity.selectcourse;import Com.csms.entity.student;import Com.csms.entity.teacher;public class Teacherwindows {private JFrame frame = new JFrame ();//Set the width of the window private final int Windo Wwide = 220;//Setting the height of the window PRIvate final int windowhigh = 560;//Teacher Object protected static Teacher Teacher = null;private String backurl = "Src//images//ico Ns//background.jpg ";p ublic teacherwindows () {teacher = new Teacherdao (). Searchteacherinformation ( Loginwindow.getloginusername (), Loginwindow.getloginpassword ()); This.compnentset (frame); Publicwindowset.windowattribute (frame, windowwide, Windowhigh, Backurl, "Teacher Interface");} Window component Set private void Compnentset (JFrame jfr) {//Set teacher photo Tag string url = "src//images//teacher//" + teacher.getteacid () + ". JPG "; Publicwindowset.addphotolabel (JFR,------------------)//Add teacher Information Publicwindowset.addlabel (JFR, +, +, 218, +, +, TE Acher.getteacid ()); Publicwindowset.addlabel (JFR, 238, Teacher.getteacname ()); Publicwindowset.addlabel (JFR, $, 258, integer.tostring (Teacher.getteacage ())); Publicwindowset.addlabel (JFR, This.addbutton, 278, Teacher.getteacgender ());//Add the button JFR (1, 335, "Change Password", and "the") ; This.addbutton (2, 375, "Release Course", JFR); This.addbutton (3, 415, "Delete release course", JFR), This.addbutton (4, 455, "entry student score", JFR), This.addbutton (5, 495, "about", JFR);} Add Teacher action button private void AddButton (int flag, int high, String str, JFrame jfr) {JButton button = new JButton (str); button.se TFont (New Font ("italics", Font.plain, +)); Button.setbounds (+, High, ()); button.setcontentareafilled (false); Button.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {switch (flag) {case 1:// Change Password new teacherfixpasswordwindows (teacher, JFR); break;case 2://Release Course new Releasecoursewindow (); Break;case 3:new Deleteyourinsertcourse (teacher); break;case 4://input student results new Addstudentgrade (); Break;case 5://About Box new Aboutwindow (); Break;}}); Jfr.add (button);}} Teacher Change Password window class Teacherfixpasswordwindows {private JFrame frame = new JFrame ();p rivate String backurl = "Src//images//ico Ns//login. PNG ";p ublic teacherfixpasswordwindows (Teacher Teacher, JFrame jfr) {Showfixpasswordwindow (This.frame, JFR, Teacher); Publicwindowset.windowattribute (This.frame, 380, BackurL, "Password modification Window");} The display window private void Showfixpasswordwindow (JFrame fixjfr, JFrame teajfr, Teacher Teacher) {frame.setlayout (null);//1. Add three tags//Add tags Publicwindowset.addlabel (frame, 16, 68, 30, 80, 30, "Original password:"); Publicwindowset.addlabel (frame, 16, 68, 65, 80, 30, "New password:"); Publicwindowset.addlabel (frame, 16, 68, 100, 80, 30, "reenter:");//2. Add three text fields//Add a text field JPasswordField OldText = new JPASSWORDFI Eld (); JPasswordField NewText = new JPasswordField (); JPasswordField reetext = new JPasswordField (); Publicwindowset.addtextfield (OldText, N, A, (), (), frame); Publicwindowset.addtextfield (NewText, N, Max, Max, +, frame); Publicwindowset.addtextfield (Reetext, Max, Max, Max, 3, frame);//(+/). Add the OK button//Add button icon icon = new ImageIcon ("src//images/ /icons//confirmfix.png "); JButton confirmbtn = new JButton (icon),///Set position confirmbtn.setbounds (120, 150, 125, 30);//Add into panel frame.add (CONFIRMBTN); Confirmbtn.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {//Add database operation to modify password// Determine if the input box has content IF (Oldtext.gettext (). Length () = = 0) {publicwindowset.promptpopup ("Please enter the original password", "Error Prompt", frame),} else if (Newtext.gettext (). Length () = = 0 | | Reetext.gettext (). Length () = = 0) {publicwindowset.promptpopup ("Please enter a new password or re-enter a new password", "Error Prompt", frame); 1. Determine if the password for the original password box is the same as the meta password if (Newtext.gettext (). Length ()! = 0 && reetext.gettext (). Length ()! = 0&&! Oldtext.gettext (). Equals (TEACHER.GETLOGINPSD ())) {publicwindowset.promptpopup ("Original password input error!", "Change password hint", frame); 2. Determine if the new password and the original password are entered in a consistent if (Newtext.gettext (). Length ()! = 0 && reetext.gettext (). Length ()! = 0&&! Reetext.gettext (). Equals (Newtext.gettext ()) && oldtext.gettext (). Equals (TEACHER.GETLOGINPSD ())) { Publicwindowset.promptpopup ("Two times password input inconsistent!", "Change password hint", frame); 3. Update password Action if (Newtext.gettext (). Length ()! = 0 && reetext.gettext (). Length ()! = 0&& Reetext.gettext (). Equals (Newtext.gettext ()) && oldtext.gettext () equals (TEACHER.GETLOGINPSD ())) {new Teacherdao (). Updatepassword (Teacher.getteacid (), Newtext.gettEXT ());//Modify Successfully release the Window Frame.dispose ();//Release Teacher window Teajfr.dispose ();//Call out Login window new Loginwindow ();}});}} About Window class Aboutwindow {JFrame frame = new JFrame ();p rivate String backurl = "src//images//icons//about.jpg";p ublic Abou Twindow () {Publicwindowset.windowattribute (This.frame, Backurl, "about Windows");}} Publish Course window class Releasecoursewindow {private JFrame frame = new JFrame ();p rivate JTable table = null;private String Backurl = "Src//images//icons//rcourse.jpg";p rivate static DefaultTableModel TableModel = Null;public ReleaseCourseWindow () { This.liftinformation (); This.rightlist (); Publicwindowset.windowattribute (This.frame, 460, Backurl, "registered course"); Right-hand list private void Rightlist () {//Set Jtabel default Type This.tablemodel = new DefaultTableModel (new Courseinformationlist (). Userinfo,new courseinformationlist (). titles);//Add JLabel component this.table = new JTable (This.tablemodel);// Prevents JLabel components from changing with the size of the window Table.setautoresizemode (jtable.auto_resize_off); Jtabel the display size of the component table Table.setpreferredscrollableviewportsizE (New Dimension (390, 0));//Make the list not move with the whole column table.gettableheader (). setreorderingallowed (false);// Make the list box unavailable for editing table.enable (false);//Add slider to Jtabel component JScrollPane SCR = new JScrollPane (this.table);//Setup Panel JPanel ToolBar = new JPanel ();//Add the Tabel component with the scrollbar to the eastern area of the panel frame.add (SCR, borderlayout.east);} Left Information window private void Liftinformation () {Publicwindowset.addlabel (This.frame, 26, 20, 25, 180, 45, "Fill course information");//Add Tag Publi Cwindowset.addlabel (This.frame, +, ten, +, +, "ID:"); Publicwindowset.addlabel (This.frame, 16, 10, 135, 45, 20, "Lesson Name:"); Publicwindowset.addlabel (This.frame, 16, 10, 170, 45, 20, "credits:"); Publicwindowset.addlabel (This.frame, 16, 10, 205, 45, 20, "Hours:"); Publicwindowset.addlabel (This.frame, 16, 10, 240, 45, 20, "type:"); Publicwindowset.addlabel (This.frame, 16, 10, 273, 45, 20, "Teacher:"); Publicwindowset.addlabel (This.frame, 16, 10, 307, 45, 20, "number:");//Add a text box//a container, save the following object list<jtextfield> list = new Arraylist<jtextfield> (); JTextField id = new JTextField (); JTextField name = newJTextField (); JTextField cridits = new JTextField (); JTextField time = new JTextField (); JTextField type = new JTextField (); JTextField Teac = new JTextField (); JTextField number = new JTextField (); Publicwindowset.addtextfield (ID, max, max, +, this.frame); Publicwindowset.addtextfield (name, Max, N, +, this.frame); Publicwindowset.addtextfield (cridits, 165, this.frame); Publicwindowset.addtextfield (time, all, Max, N, This.frame); Publicwindowset.addtextfield (Type, max, 235, N, This.frame); Publicwindowset.addtextfield (TEAC, Max, this.frame); Publicwindowset.addtextfield (number, 305, this.frame), List.add (ID); List.add (name); List.add (cridits); List.add (time); List.add (type); List.add (TEAC); List.add (number);//Add Confirmation Buttonthis.addbutton (1, 350, "Commit", list, Teacherwindows.teacher); This.addbutton (2, 390, "Registered course", list, teacherwindows.teacher); Add buttonprivate void AddButton (int flag, int high, String str, list<jtextfield> L, Teacher teachER) {JButton Confrim = new JButton (str); Confrim.setfont (New Font ("Italic", Font.plain, +)); Confrim.setbounds (+, high, 120, Confrim.setcontentareafilled (false); Frame.add (Confrim); Confrim.addactionlistener (new ActionListener () { public void actionperformed (ActionEvent e) {switch (flag) {Case 1:if (l.get (0). GetText (). Length () = = 0 | | l.get (1). GetText (). Length () = = 0| | L.get (2). GetText (). Length () = = 0 | | L.get (3). GetText (). Length () = = 0| | L.get (4). GetText (). Length () = = 0 | | L.get (5). GetText (). Length () = = 0| | L.get (6). GetText (). Length () = = 0) publicwindowset.promptpopup ("Please fill in the Complete course information!", "Input course tip", frame); else {new Coursedao (). Insertcourseinformation (l, teacher); for (int i = 0; i < l.size (); i++) {L.get (i). SetText ("");}} Break;case 2:list<course> List = new Coursedao (). Searchcourseinformation (); Course Course = null;for (int i = 0; i < list.size (); i++) {Course = List.get (i); ReleaseCourseWindow.tableModel.addRow (new object[] {i, Course.getcourid (), Course.getcourname (), Course.getcourTeacher (), Course.getcourtype ()}); Confrim.setenabled (false); break;}}); Jtabel List Property Set class Courseinformationlist extends Abstracttablemodel {public string[] titles = {"Ordinal", "Course ID", "Course name", "old "Type"};p ublic object[][] userInfo = {}; Define data public int GetRowCount () {return 0;} public int getColumnCount () {return 0;} Public Object getvalueat (int rowIndex, int columnindex) {return null;}}} Delete inserted Course class Deleteyourinsertcourse {private JFrame frame = new JFrame ();p rivate JFrame coursepopupjfr = null;private S Tring URL = "src//images//icons//admin.jpg";p rivate string[] coursestr = {"Course id", "Course name", "Credits", "Hours", "number"};p rivate Stati C DefaultTableModel Coursetablemodel; JTextField CourseID = Null;public deleteyourinsertcourse (Teacher Teacher) {this.windowinformation (Teacher); Publicwindowset.windowattribute (This.frame, +, +, url, "delete registered course"); private void Windowinformation (Teacher Teacher) {//Add large label Publicwindowset.addlabel (frame, 26, 110, 5, 300, 30, "Delete registered course"); /Add Small label PUBLICWINDOWSET.ADDLAbel (Frame, 16, 45, 55, 90, 30, "Course ID:");//Add Buttonthis.addbutton (1, frame, 55, "View registered course", teacher, this); This.addbutton (2, Frame, 205, "Delete registered course", teacher, this);//Add text field CourseID = new JTextField (); Publicwindowset.addtextfield (CourseID, N, this.frame);} public void Showcoursewindow (Teacher Teacher) {coursepopupjfr = new JFrame (); Publicwindowset.windowattribute (COURSEPOPUPJFR, n, $, NULL, "Student Information window"); Coursetablemodel = Publicwindowset.addtablelist (COURSEPOPUPJFR, COURSESTR); list<course> list = new Coursedao (). Searchcourse (Teacher.getteacid ()); Course Course = null;for (int i = 0; i < list.size (); i++) {Course = List.get (i); Coursetablemodel.addrow (new object[] { Course.getcourid (), Course.getcourname (), Course.getcourcridits (), Course.getcourtimes (), Course.getcournumber ()}) ;}} private void AddButton (int flag, JFrame jfr, int x, String str, Teacher Teacher, Deleteyourinsertcourse dyi) {JButton Butt on = new JButton (str); Button.setfont (New Font ("italics", Font.plain, 16)); button.setcontentareafilled (false); Button.setbounds (x, +, +), Button.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {switch (flag) {case 1:dyi.showcoursewindow (teacher); Break;case 2:if ( Courseid.gettext (). Length ()! = 0) {new Coursedao (). Deletecourseinformation (Courseid.gettext ()); Coursepopupjfr.dispose (); Courseid.settext ("");d Yi.showcoursewindow (teacher); Elsepublicwindowset.promptpopup ("Please fill in the course to be deleted id!", "Delete Course tip", JFR); break;}}); Jfr.add (button);}} Input student Results class Addstudentgrade {JFrame frame = new JFrame ();p rivate defaulttablemodel gradetablemodel;private JFrame popu PJFR = null;private String CourseID = null;private JTextField coursetext = null;private JTextField GradeText = Null;privat E JTextField studenttext = null;private String url = "src//images//icons//admin.jpg";p rivate string[] gradeStr = {"Course id", "Course name", "classroom Teacher", "Student ID", "Student name", "Course Score"};p ublic Addstudentgrade () {this.displayinformation (frame); Teacher Display information private void DisplayinformatioN (JFrame jfr) {Publicwindowset.addlabel (JFR, 26, 110, 5, 300, 30, "Student record Entry"); Publicwindowset.addlabel (JFR, 16, 45, 55, 90, 30, "Course ID:"), Coursetext = new JTextField (); Publicwindowset.addtextfield (Coursetext, N, JFR); Publicwindowset.addlabel (JFR, 16, 45, 90, 90, 30, "Student ID:"), Studenttext = new JTextField (); Publicwindowset.addtextfield (Studenttext, N, JFR); Publicwindowset.addlabel (JFR, 16, 45, 125, 90, 30, "Course Score:"), Gradetext = new JTextField (); Publicwindowset.addtextfield (Gradetext, he, JFR), AddButton (1, JFR, "Elective students", page, this); AddButton (2, JFR, "add Results ", Mark, this); Publicwindowset.windowattribute (JFR, 380, 235, URL, "Teacher Interface");} Student Information Display window private void Showinformation () {popupjfr = new JFrame (); Publicwindowset.windowattribute (POPUPJFR, 475, $, NULL, "Student Information window"); Gradetablemodel = Publicwindowset.addtablelist ( POPUPJFR, gradestr); CourseID = Coursetext.gettext (); list<object> list = new Selectcoursedao (). Searchunioninformation (CourseID); for (int i = 0; I < list.size (); i = i + 3) {Course Course = (Course) list.get (i); Student Student = (Student) list.get (i + 1); Selectcourse sc = (selectcourse) list.get (i + 2); Gradetablemodel.addrow (new object[] {Course.getcourid (), Course.getcourname (), Course.getcourteacher (), Student.getstuid (), Student.getstuname (), Sc.getstudentgrade ()});}} private void AddButton (int flag, JFrame jfr, String str, int x, addstudentgrade th) {JButton button = new JButton (str); Ton.setfont (New Font ("Italic", Font.plain, +)); button.setcontentareafilled (false); Button.setbounds (x, 170, 100, 30); Button.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {switch (flag) {Case 1:if ( Coursetext.gettext (). Length () = = 0) {publicwindowset.promptpopup ("Please enter the course ID before viewing elective students", "Error Prompt", JFR);} else { Th.showinformation ();} Break;case 2:if (Coursetext.gettext (). Length () = = 0) {publicwindowset.promptpopup ("Please enter the course ID before entering the student score", "Error Prompt", JFR);} if (Coursetext.gettext (). Length ()! = 0 && studenttext.gEttext (). Length () = = 0) {publicwindowset.promptpopup ("Please enter student ID before entering student's score", "error message", JFR);} if (Coursetext.gettext (). Length ()! = 0 && studenttext.gettext (). Length ()! = 0&& Gradetext.gettext (). Length () = = 0) {publicwindowset.promptpopup ("Please student score, in entry score", "Error hint", JFR);} else {new Selectcoursedao (). Addstudentgrade ( Studenttext.gettext (), Coursetext.gettext (), Float.valueof (Gradetext.gettext ())), Studenttext.settext (""); Gradetext.settext ("");p Opupjfr.dispose (); Th.showinformation ();} Break;}}); Jfr.add (button);}}
----Teacherwindow of Students ' course selection system