Java GUI implements the student achievement management system,

Source: Internet
Author: User

Java GUI implements the student achievement management system,

I have been learning java for more than a year and have been doing web exercises. In a project, I found that the GUI-related knowledge is required and the results cannot be obtained, there are not many articles in this area on the Internet, so I had to learn them from the beginning. However, I found that the GUI is very interesting, he does not rely on the Internet like a WEB program, and there are still many la s which are not very different from android. Only then can he find that he fell in love with GUI development, go directly to the code. I believe that android or related interface development understands the truth.

Let's take a look at the effect.

1. log on to the main interface

Package edu.gz u. stuManager; import java. awt. eventQueue; import javax. swing. JFrame; import javax. swing. JLabel; import javax. swing. JOptionPane; import java. awt. toolkit; import javax. swing. JTextField; import edu.gz u. stuManager. dao. userLoginValid; import edu.gz u. stuManager. domain. studentInfo; import edu.gz u. stuManager. view. studentMainView; import java. awt. choice; import java. awt. font; import java. awt. B Utton; import java. awt. event. mouseAdapter; import java. awt. event. mouseEvent; public class MainUI {private JFrame frame; private JTextField textField; private JTextField textField_1;/*** Launch the application. */public static void main (String [] args) {EventQueue. invokeLater (new Runnable () {public void run () {try {MainUI window = new MainUI (); window. frame. setVisible (true);} catch (effecti On e) {e. printStackTrace () ;}});}/*** Create the application. */public MainUI () {initialize ();}/*** Initialize the contents of the frame. */private void initialize () {frame = new JFrame (); frame. setTitle ("\ u6210 \ u7EE9 \ u7BA1 \ u7406 \ u7CFB \ u7EDF \ uFF08 \ u767B \ u5F55 \ uFF09"); frame. setIconImage (Toolkit. getdefatooltoolkit (). getImage (MainUI. class. getResource ("/image/func_list7_privmana.png "))); Frame. setBounds (400,250,450,300); frame. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); frame. getContentPane (). setLayout (null ); JLabel lblNewLabel = new JLabel ("\ Alibaba \ u751F \ u6210 \ u7EE9 \ u7BA1 \ Alibaba \ u7CFB \ Alibaba \ u7528 \ u6237 \ Alibaba \ u5F55 \ uFF01"); lblNewLabel. setFont (new Font ("", Font. PLAIN, 16); lblNewLabel. setBounds (111, 17,287, 15); frame. getContentPane (). add (lblNewLabel); JLabel lblNewLabel _ 1 = new JLabel ("\ u7528 \ u6237 \ u540D \ uFF1A"); lblNewLabel_1.setFont (new Font ("", Font. PLAIN, 14); lblNewLabel_1.setBounds (87, 67, 67, 15); frame. getContentPane (). add (lblNewLabel_1); textField = new JTextField (); textField. setBounds (154, 64,141, 21); frame. getContentPane (). add (textField); textField. setColumns (10); JLabel label = new JLabel ("\ u5BC6 \ u7801 \ uFF1A"); label. setFont (new Font ("", Fon T. PLAIN, 14); label. setBounds (87,108, 67, 15); frame. getContentPane (). add (label); textField_1 = new JTextField (); textField_1.setColumns (10); textField_1.setBounds (154,103,141, 21); frame. getContentPane (). add (textField_1); JLabel lblNewLabel_2 = new JLabel ("\ u6211 \ u7684 \ u8EAB \ u4EFD \ u662F \ uFF1A"); trim (new Font ("", Font. PLAIN, 14); lblNewLabel_2.setBounds (105,150, 97, 15 ); Frame. getContentPane (). add (lblNewLabel_2); final Choice choice = new Choice (); choice. setBounds (210,147, 74, 21); choice. add ("student"); choice. add ("instructor"); choice. add ("System Administrator"); frame. getContentPane (). add (choice); Button button = new Button ("\ u767B \ u5F55"); button. setBounds (87,194, 76, 23); button. addMouseListener (new MouseAdapter () {@ Override public void mouseClicked (MouseEvent e) {String user = textF Ield. getText (); String password = textField_1.getText (); String shenfen = choice. getSelectedItem (); if (user. equals ("") | user = null) {JOptionPane. showMessageDialog (frame, shenfen + ": Hello, the account cannot be blank! "); Return;} else if (password. equals ("") | password = null) {JOptionPane. showMessageDialog (frame, shenfen + ": Hello, the password cannot be blank! "); Return;} else {StudentInfo stu = new StudentInfo (Integer. parseInt (user), Integer. parseInt (password), shenfen); UserLoginValid dao = new UserLoginValid (); String result = dao. isValid (stu); if ("Logon successful! ". Equals (result) {JOptionPane. showMessageDialog (frame, result); StudentMainView index = new StudentMainView (stu); JFrame frame2 = index. getFrame (); frame2.setVisible (true); frame. dispose ();} else {JOptionPane. showMessageDialog (frame, result) ;}}}); frame. getContentPane (). add (button); Button button_1 = new Button ("\ u53D6 \ u6D88"); button_1.setBounds (219,194, 76, 23); frame. getContentPane (). add (button_1 );}}

2. login verification Logic

Package edu.gz u. stuManager. dao; import edu.gz u. stuManager. domain. studentInfo; public class UserLoginValid {public String isValid (StudentInfo stu) {int idnum = stu. getIdnum (); int password = stu. getPassword (); String idntify = stu. getIdentify (); String result = null; if ("student ". equals (idnals) {if (idnum = 1207010209 & password = 123) {stu. setName ("Liu mingsheng"); result = "Logon successful! ";} Else {result =" this user does not exist in the student account. Please confirm your identity and log on again! ";}} Else if (" instructor ". equals (idnals) {if (idnum = 1174386356 & password = 123) {stu. setName ("Miss Liu mingsheng"); result = "Logon successful! ";} Else {result =" this user does not exist in the instructor account. Please confirm your identity and log on again! ";}} Else if (" System Administrator ". equals (idnals) {if (idnum = 999999 & password = 123) {stu. setName ("System Administrator"); result = "Logon successful! ";} Else {result =" this user does not exist in the system administrator account. Please confirm your identity and log on again! ";}} Return result ;}}

3. User object (this is a simple bean)

package edu.gzu.stuManager.Domain;  public class StudentInfo {  private int idnum;  private String name;  private int password;  private String identify;    public StudentInfo(int idnum,int password, String identify) {   super();   this.idnum = idnum;   this.password = password;   this.identify = identify;  }  public int getIdnum() {   return idnum;  }  public void setIdnum(int idnum) {   this.idnum = idnum;  }  public String getName() {   return name;  }  public void setName(String name) {   this.name = name;  }  public int getPassword() {   return password;  }  public void setPassword(int password) {   this.password = password;  }  public String getIdentify() {   return identify;  }  public void setIdentify(String identify) {   this.identify = identify;  }     } 

4. Main Interface after Successful Logon

Package edu.gz u. stuManager. view; import java. awt. button; import java. awt. canvas; import java. awt. choice; import java. awt. color; import java. awt. toolkit; import java. awt. event. itemEvent; import java. awt. event. itemListener; import javax. swing. JFrame; import javax. swing. JLabel; import javax. swing. JOptionPane; import javax. swing. JPanel; import javax. swing. JTextField; import edu.gz u. stuManager. domain. st UdentInfo; public class StudentMainView {private JFrame frame; private JTextField textField; private JTextField textField_1; private JTextField textField_2; private JTextField textField_3; private StudentInfo info;/*** Create the frame. * @ wbp. parser. entryPoint */public StudentMainView (StudentInfo info) {this.info = info;} public JFrame getFrame () {initialize (); return frame;}/*** Initialize The contents of the frame. * @ wbp. parser. entryPoint */public void initialize () {frame = new JFrame (); frame. setTitle ("\ u6210 \ u7EE9 \ u7BA1 \ u7406 \ u7CFB \ u7EDF \ uFF08 \ u5B66 \ u751F \ u7248 \ uFF09"); frame. setIconImage (Toolkit. getdefatooltoolkit (). getImage (StudentMainView. class. getResource ("/image/func_list7_privmana.png"); frame. setBounds (300,150,550,300); frame. setdefaclocloseoperation (JFrame. EXIT_ON _ CLOSE); frame. getContentPane (). setLayout (null); JLabel lblNewLabel = new JLabel ("Welcome [" + info. getName () + "] to log on to the Student Score Management System! "); LblNewLabel. setBounds (54,10,322, 15); frame. getContentPane (). add (lblNewLabel); JPanel panel = new JPanel (); panel. setBounds (29, 52,250,180); frame. getContentPane (). add (panel); panel. setLayout (null); JLabel lblNewLabel_1 = new JLabel ("\ u6210 \ u7EE9 \ u6570 \ u636E"); lblNewLabel_1.setBounds (94, 10, 65, 15); panel. add (lblNewLabel_1); JLabel lblNewLabel_2 = new JLabel ("\ u5B66 \ u53F7 \ uFF1A"); lblNewLabel_2.setBounds (22, 37, 40, 15); panel. add (lblNewLabel_2); textField = new JTextField (); textField. setBounds (72, 35,154, 21); textField. setText (info. getIdnum () + ""); panel. add (textField); textField. setColumns (10); JLabel lblNewLabel_3 = new JLabel ("\ u59D3 \ u540D \ uFF1A"); lblNewLabel_3.setBounds (22, 67, 44, 15); panel. add (lblNewLabel_3); textField_1 = new JTextField (); textField_1.setBounds (72, 66,154, 21); textField_1.setText (info. getName (); panel. add (textField_1); textField_1.setColumns (10); Canvas canvas = new Canvas (); canvas. setBackground (Color. BLUE); canvas. setBounds (22,100,205, 1); panel. add (canvas); JLabel lblNewLabel_4 = new JLabel ("\ u8BFE \ u7A0B \ u540D"); lblNewLabel_4.setBounds (22,116, 47, 15); panel. add (lblNewLabel_4); JLabel lblNewLabel_5 = new JLabel ("\ u6210 \ u7EE9"); lblNewLabel_5.setBounds (160,116, 43, 15); panel. add (lblNewLabel_5); textField_2 = new JTextField (); textField_2.setBounds (22,140,123, 21); panel. add (textField_2); textField_2.setColumns (10); textField_3 = new JTextField (); textField_3.setBounds (159,140, 66, 21); panel. add (textField_3); textField_3.setColumns (10); JPanel panel_1 = new JPanel (); panel_1.setBounds (317, 52,110,180); frame. getContentPane (). add (panel_1); panel_1.setLayout (null); JLabel lblNewLabel_6 = new JLabel ("\ u64CD \ u4F5C \ u83DC \ u5355"); average (15, 10, 54, 15 ); panel_1.add (lblNewLabel_6); Button button Button = new button ("\ u7B2C \ u4E00 \ u95E8 \ u8BFE \ u7A0B"); Button. setBounds (10, 31, 76, 23); panel_1.add (button); Button button_1 = new Button ("\ u4E0B \ u4E00 \ u95E8 \ u8BFE \ u7A0B"); limit (10, 61, 76, 23); panel_1.add (button_1); Button button_2 = new Button ("\ u4E0A \ u4E00 \ u95E8 \ u8BFE \ u7A0B "); button_2.setActionCommand ("\ u4E0A \ u4E00 \ u95E8 \ u8BFE \ u7A0B"); button_2.setBounds (10, 90, 76, 23); panel_1.add (button_2 ); button button_3 = new Button ("\ u6700 \ u540E \ u4E00 \ u95E8 \ u8BFE"); button_3.setBounds (10,117, 76, 23); panel_1.add (button_3 ); choice choice = new Choice (); choice. setBounds (10,149, 76, 21); choice. add ("Select Course"); choice. add ("Advanced Mathematics"); choice. add (""); choice. add ("Marxism-Leninism"); choice. add ("Mao Zedong Thought"); choice. add ("computer graphics"); choice. addItemListener (new ItemListener () {@ Override public void itemStateChanged (ItemEvent e) {Object [] objs = e. getItemSelectable (). getSelectedObjects (); for (Object ob: objs) {// JOptionPane. showMessageDialog (frame, ob. toString (); if ("Advanced Mathematics ". equals (ob. toString () {textField_2.setText ("Advanced Mathematics"); textField_3.setText ("98");} else if (" ". equals (ob. toString () {textField_2.setText (""); textField_3.setText ("87");} else if ("Marxism-Leninism ". equals (ob. toString () {textField_2.setText ("Marxism-Leninism"); textField_3.setText ("88");} else if ("Mao Zedong Thought ". equals (ob. toString () {textField_2.setText ("Mao Zedong Thought"); textField_3.setText ("73");} else if ("computer graphics ". equals (ob. toString () {textField_2.setText ("computer graphics"); textField_3.setText ("97") ;}}); panel_1.add (choice );}}

In this way, you can easily implement login verification. I plan to read data from the database. Due to the time relationship, this is simple and directly verified. If there is time in the future, I will do other operations.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.