----Loginwindow of Students ' course selection system

Source: Internet
Author: User

/** * @author Li Pei * * @version v1 * * @time 2016/12/1 15:37 * * @program Create a teacher class for the corresponding data table entity to facilitate DAO's connection to the database * */package com.csms . windows;//import the package to be used import Java.awt.font;import java.awt.event.actionevent;import java.awt.event.ActionListener; Import Com.csms.dao.*;import javax.swing.*;//student elective System login interface public class Loginwindow {JFrame frame = new JFrame ();//Window size PRI vate static final int windowswide = 400;private static final int windowshigh = 200;//determines the selection of RadioButton: 1 for Administrators, 2 for students, 3 for teachers private static int flag = 0;//defines user name input box and Password box component variable final JTextField usertext;final jpasswordfield pswtext;//set password label and user name label JLA Bel Psdlabel; JLabel textlabel;//radio button component variable Jradiobutton radiobutton;//user login variable, through these two variables, in the student interface, the teacher interface to get the login username and password private static String Loginusername;private Static String loginpassword;//creates a radio button group Buttongroup buttgroup = new Buttongroup (); JPanel Southpanel = new JPanel ();//Set the logo tag of the login screen icon icon = new ImageIcon ("Src//images//icons//loginicon.png");p ublic Loginwindow () {//1. Set label label for Login box of Hunan Polytechnic Institute logo label JlabeL label = new JLabel (icon), Label.setbounds (0, 260, max), Frame.add (label),//2. Set the position of the text label and text box//user name tag and user name login box, and set them up in a good location , add into panel Publicwindowset.addlabel (frame, 16, 65, 70, 90, 30, "username:"); usertext = new JTextField (); Publicwindowset.addtextfield (Usertext, N, +, +, +, frame);//password tags and password login boxes, and set them up in position, Add into panel Publicwindowset.addlabel (frame, 16, 65, 105, 90, 30, "Password:");p Swtext = new JPasswordField (); Publicwindowset.addtextfield (Pswtext, N, Max, Max, +, frame);//3. Set radio button//Create radio button This.addradiobutton ("admin", 1, False ); This.addradiobutton ("Student", 2, false); This.addradiobutton ("Teacher", 3, False); Southpanel.setbounds (60, 140, 200, 30); Frame.add (Southpanel);//4. Create Login button This.addbutton ("Login", frame);//5. Set window-related properties, The Windowattribute function is a window property set function that encapsulates the Publicwindowset class//Settings window title Publicwindowset.windowattribute (frame, windowswide, Windowshigh, NULL, "Hunan Polytechnic College Student selection system");  Set radio button Listener and add radio button private void AddRadioButton (String name, int flag, Boolean bool) {RadioButton = new Jradiobutton (name, BOOL);//Set radio button transparent RadiobutTon.setcontentareafilled (false);//Set radio button font and font related properties Radiobutton.setfont (new Font ("Italic", Font.plain, 12)); Radiobutton.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {Loginwindow.setflag ( flag);}); Buttgroup.add (RadioButton); Southpanel.add (RadioButton);} Add the login confirmation and Cancel button and also set the button listener private void AddButton (String buttonname, JFrame jfr) {JButton button = new JButton (buttonname); b Utton.setbounds (260, Button.addactionlistener, Max), Button.setfont (New Font ("Italic", Font.plain,)); ActionListener () {public void actionperformed (ActionEvent event) {try {///Execute login//Set user name and password, save Loginusername = Usertext.gettext (); Loginpassword = Pswtext.gettext (); Loginwindow.setloginusername (Loginusername); Loginwindow.setloginpassword (Loginpassword); if (loginwindow.getflag () = = 1) {//1. The Administrator//determines whether the contents of the input box are empty, The code in this can also continue to encapsulate if (loginusername.length () = = 0 | | loginpassword.length () = = 0) {// The Promptpopup method is to encapsulate the publicwindowset in the prompt box to display the function publicwindowset.promptpopup ("Enter user name and password!", "Login Prompt", JFR);} Determine if the password and user name you entered are correct else if (new Adminitartordao (). Loginconfirm (Loginusername, Loginpassword)) { Publicwindowset.promptpopup ("Login Successful!!!", "Login Prompt", JFR); new Admintratorwindow (); Jfr.dispose ();} else {publicwindowset.promptpopup ("username or password is wrong, please reenter!!!", "Login Prompt", JFR);}} else if (loginwindow.getflag () = = 2) {//2. Student//Determine if the contents of the input box are empty if (loginusername.length () = = 0 | | loginpassword.length () = = 0 {Publicwindowset.promptpopup ("Please enter user name and password!", "Login Prompt", JFR);} Verify the identity and determine whether the correct user name and password else if (new Studentdao (). Loginconfirm (Loginusername, Loginpassword)) { Publicwindowset.promptpopup ("Login Successful!!!", "Login Prompt", JFR); Studentwindow SW = new Studentwindow (), Sw.setsize (Sw.getwindowwide (), Sw.getwindowhigh ());//Release Login window Jfr.dispose ();} else {publicwindowset.promptpopup ("username or password is wrong, please reenter!!!", "Login Prompt", JFR);}} else if (loginwindow.getflag () = = 3) {//3. Teacher//Determine if the contents of the input box are empty if (loginusername.length () = = 0 | | loginpassword.length () = = 0 {Publicwindowset.promptpopup ("Please enter user name and password!", "Login Prompt", JFR);} Verify the identity and determine whether the correct user name and password else if (new Teacherdao (). LOginconfirm (Loginusername, Loginpassword)) {publicwindowset.promptpopup ("Login Successful!!!", "Login Prompt", JFR); New Teacherwindows ( ); Jfr.dispose ();} else {publicwindowset.promptpopup ("username or password is wrong, please reenter!!!", "Login Prompt", JFR);}} else {publicwindowset.promptpopup ("Please select your identity: Student, teacher, Administrator!", "Login Prompt", JFR);}} catch (Exception e) {e.printstacktrace ();}}}); Jfr.add (button);} Gets the flag identifier private static int Getflag () {return flag;} Set flag identity private static void Setflag (int flag) {Loginwindow.flag = flag;} Gets the login user name public static String Getloginusername () {return loginusername;} Set logon user name public static void Setloginusername (String loginusername) {loginwindow.loginusername = Loginusername;} Gets the login user name public static String Getloginpassword () {return loginpassword;} Set logon user name public static void Setloginpassword (String loginpassword) {Loginwindow.loginpassword = Loginpassword;}}

  

----Loginwindow of Students ' course selection system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.