Java GUI makes a simple management system and javagui Management System

Source: Internet
Author: User

Java GUI makes a simple management system and javagui Management System

The examples in this article share the specific code of the Java GUI Management System for your reference. The specific content is as follows:

1. Complete MainUI on the home page first (the Code is as follows)

Package com. pag_1; import javax. swing. *; import java. awt. *; import java. awt. event. actionEvent; import java. awt. event. actionListener; public class MainUI extends JFrame implements ActionListener {// defines components JButton jb1, jb2, jb3 = null; JRadioButton jrb2, jrb2 = null; JPanel jp1, jp2, jp3, jp4 = null; JTextField jtf = null; JLabel jlb1, jlb2, jlb3 = null; JPasswordField jpf = null; ButtonGroup bg = null; // set the user name and password final St Ring stu_name = "Wang Xiaoming"; final String stu_pwd = "1"; final String stu_num = "14140301"; final String tea_name = ""; final String tea_pwd = "1 "; final String tea_num = "00001"; public static void main (String [] args) {MainUI mUI = new MainUI ();} public MainUI () {// Create component jb1 = new JButton ("login"); jb2 = new JButton ("reset"); jb3 = new JButton ("exit "); // set the listener jb1.addActionListener (this); jb2.addActionListener (this); jb3.addA CtionListener (this); jrb1 = new JRadioButton (""); jrb2 = new JRadioButton ("student"); bg = new ButtonGroup (); bg. add (jrb1.); bg. add (jrb2); jrb2.setSelected (true); // The default permission on the initial Page is jp1 = new JPanel (); jp2 = new JPanel (); jp3 = new JPanel (); jp4 = new JPanel (); jlb1 = new JLabel ("username:"); jlb2 = new JLabel ("Password:"); jlb3 = new JLabel ("permission limit: "); jtf = new JTextField (10); jpf = new JPasswordField (10); // Add it to JPanel jp1.add (jlb1); jp1. Add (jtf); jp2.add (jlb2); jp2.add (jpf); jp3.add (jlb3); // add the label jp3.add (jv1); jp3.add (jrb2); jp4.add (jb1 ); // Add the button jp4.add (jb2); jp4.add (jb3); // Add this to JFrame. add (jp1); this. add (jp2); this. add (jp3); this. add (jp4); this. setLayout (new GridLayout (); // select the GridLayout layout manager this. setTitle ("Student Score Management System"); this. setSize (300,200); this. setLocation (400,200); this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE ); // Set the JVM to exit this when the window is closed. setVisible (true); this. setResizable (true);} public void actionreceivmed (ActionEvent e) {// event judgment if (e. getActionCommand () = "login") {// if the selected instructor logs on if (jrb1.isSelected () {tealogin (); // connect to the instructor's method page} else if (jrb2.isSelected () // students log on to the system {stulogin (); // connect to the student's method page} else if (e. getActionCommand () = "reset") {clear () ;}// student logon Judgment Method public void stulogin () {if (stu_name.equals (jtf. getT Ext () & stu_pwd.equals (jpf. getText () {JOptionPane. showMessageDialog (null, "Logon successful! "," Message ", JOptionPane. WARNING_MESSAGE); dispose (); clear (); StdUI ui = new StdUI (); // create a new interface} else if (jtf. getText (). isEmpty () & jpf. getText (). isEmpty () {JOptionPane. showMessageDialog (null, "Enter your username and password! "," Message ", JOptionPane. WARNING_MESSAGE);} else if (jtf. getText (). isEmpty () {JOptionPane. showMessageDialog (null," Enter the user name! "," Message ", JOptionPane. WARNING_MESSAGE);} else if (jpf. getText (). isEmpty () {JOptionPane. showMessageDialog (null," enter the password! "," Message ", JOptionPane. WARNING_MESSAGE);} else {JOptionPane. showMessageDialog (null," incorrect user name or password! \ N enter "," message ", JOptionPane again. ERROR_MESSAGE); // clear the input box clear () ;}// instructor logon Judgment Method public void tealogin () {if (tea_name.equals (jtf. getText () & tea_pwd.equals (jpf. getText () {JOptionPane. showMessageDialog (null, "Logon successful! "," Message ", JOptionPane. WARNING_MESSAGE); clear (); dispose (); TerUI ui = new TerUI (); // create a new interface} else if (jtf. getText (). isEmpty () & jpf. getText (). isEmpty () {JOptionPane. showMessageDialog (null, "Enter your username and password! "," Message ", JOptionPane. WARNING_MESSAGE);} else if (jtf. getText (). isEmpty () {JOptionPane. showMessageDialog (null," Enter the user name! "," Message ", JOptionPane. WARNING_MESSAGE);} else if (jpf. getText (). isEmpty () {JOptionPane. showMessageDialog (null," enter the password! "," Message ", JOptionPane. WARNING_MESSAGE);} else {JOptionPane. showMessageDialog (null," incorrect user name or password! \ N enter "," message ", JOptionPane again. ERROR_MESSAGE); clear (); // clear the input box} // clear the text box and Password box public void clear () {jtf. setText (""); jpf. setText ("");}}

Figure 1

 

The username and password are as follows:

2. Complete StuUI on the student interface. This page sets a button connection on the MainUI interface (the Code is as follows)

Package com. pag_1; import java. awt. *; import java. awt. event. *; import javax. swing. *; import javax. swing. JButton; import java. awt. color. *; import javax. swing. JOptionPane; import com. pag_1.MainUI; public class StdUI extends JFrame implements ActionListener {// defines the JButton jb1 = new JButton (); JButton jb2 = new JButton (); JPanel jp1, jp2, jp3, jp4 = null; JLabel jlb1, jlb2, jlb3, jlb4, jlb5, jlb6 = null; public static v Oid main (String [] args) {StdUI ui = new StdUI ();} ******** ************* // constructor public StdUI () // It cannot be declared as void !!!!! Otherwise, the page cannot be displayed {// Create component jb1 = new JButton ("course schedule"); jb1.setForeground (Color. BLUE); jb2 = new JButton ("score query"); jb2.setForeground (Color. BLUE); jp1 = new JPanel (); jp2 = new JPanel (); jp3 = new JPanel (); jlb1 = new JLabel ("name :"); jlb2 = new JLabel ("student ID:"); jlb3 = new JLabel ("latest announcement:"); jlb3.setForeground (Color. red); jlb4 = new JLabel (""); jlb5 = new JLabel (new MainUI (). stu_name); jlb6 = new JLabel (new MainUI (). stu_num); jp1.add (jlb1); jp1.add (jlb5); jp1.add (jlb2); jp1.add (jlb6); merge (jb1); jp2.add (jb2); jp3.add (jlb3 ); jp3.add (jlb4); this. add (jp1); this. add (jp2); this. add (jp3); // set the layout manager this. setLayout (new GridLayout (4, 3, 50, 50); this. setTitle ("Student Score Management System"); this. setSize (400,300); this. setLocation (200,200); this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); this. setVisible (true); jb1.addActionListener (this); jb2.addActionListener (this);} public void actionreceivmed (ActionEvent e) {if (e. getSource () = jb1) {// close the current interface dispose (); new KeChengBiaoUI ();} else if (e. getSource () = jb2) {// close the current interface dispose (); new ChengJiBiaoUI ();}}}

Run MainUI and enter the user student. The following student interface is displayed. The course list and score query buttons on the interface are two clickable buttons, which are connected to the next page and followed by the subsequent steps.

3. Complete the TerUI of the instructor interface. Like the student page, a button event is set on the MainUI page to connect to the MainUI page. (the Code is as follows)

Package com. pag_1; import java. awt. *; import java. awt. event. *; import javax. swing. *; import javax. swing. JButton; import com. pag_1.MainUI; public class TerUI extends JFrame implements ActionListener {// defines the JButton jb1, jb2 = null; JPanel jp1, jp2, jp3, jp4 = null; JLabel jlb1, jlb2, jlb3, jlb4, jlb5, jlb6 = null; public static void main (String [] args) {TerUI ui = new TerUI ();} public TerUI () {// Create component jb1 = new JButton ("Course Management"); jb1.setForeground (Color. BLUE); jb2 = new JButton ("Student List"); jb2.setForeground (Color. BLUE); jp1 = new JPanel (); jp2 = new JPanel (); jp3 = new JPanel (); jlb1 = new JLabel ("name :"); jlb2 = new JLabel ("employee ID:"); jlb3 = new JLabel ("latest announcement:"); jlb3.setForeground (Color. red); jlb4 = new JLabel ("Notice of physical testing in Our Hospital"); jlb5 = new JLabel (new MainUI (). tea_name); jlb6 = new JLabel (new MainUI (). tea_num); jp1.add (jlb1); jp1.add (jlb5); jp1.add (jlb2); jp1.add (jlb6); merge (jb1); jp2.add (jb2); jp3.add (jlb3 ); jp3.add (jlb4); this. add (jp1); this. add (jp2); this. add (jp3); this. setLayout (new GridLayout (, 50, 50); // sets the layout manager this. setTitle ("Student Score Management System"); this. setSize (400,300); this. setLocation (200,200); this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); this. setVisible (true); jb1.addActionListener (this); jb2.addActionListener (this);} public void actionreceivmed (ActionEvent e) {if (e. getSource () = jb1) {dispose (); new KeChengGuanLiUI (); // create a new interface} else if (e. getSource () = jb2) {dispose (); new XueShengMingDanUI (); // create a new interface }}}

Run MainUI and enter the user instructor. The following instructor interface is displayed. The "Course Management" and "student list" buttons on the interface are two clickable buttons, which are connected to the next page and followed by the subsequent steps.

4. Complete the curriculum interface on the student interface (the Code is as follows)

Package com. pag_1; import javax. swing. JFrame; import javax. swing. JScrollPane; import javax. swing. JTable; import javax. swing. table. tableColumn; public class KeChengBiaoUI extends JFrame {public KeChengBiaoUI () {intiComponent ();} private void intiComponent () {String [] columnNames = {"number of courses", "Monday ", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday "}; object [] [] obj = new Object [8] [8]; for (int I = 0; I <8; I ++) {for (int j = 0; j <8; j ++) {switch (j) {case 0: obj [0] [0] = "Lesson 1 "; obj [0] [1] = "Optical Fiber Communication"; obj [0] [2] = "Electromagnetic Field"; obj [0] [3] = "Iot "; obj [0] [4] = "DSP experiment"; obj [0] [5] = ""; obj [0] [6] = "Mobile Phone repair "; obj [0] [7] = ""; break; case 1: obj [1] [0] = "Lesson 2 "; obj [1] [1] = "Optical Fiber Communication"; obj [1] [2] = "Electromagnetic Field"; obj [1] [3] = "Iot "; obj [1] [4] = "DSP experiment"; obj [1] [5] = ""; obj [1] [6] = "Mobile Phone repair "; obj [1] [7] = ""; break; case 2: obj [2] [0] = "Lesson 3 "; obj [2] [1] = "Android"; obj [2] [2] = ""; obj [2] [3] = ""; obj [2] [4] = "DSP experiment"; obj [2] [5] = "Mobile Phone repair"; obj [2] [6] = "Mobile Phone repair "; obj [2] [7] = ""; break; case 3: obj [3] [0] = "Lesson 4 "; obj [3] [1] = "Android"; obj [3] [2] = ""; obj [3] [3] = ""; obj [3] [4] = ""; obj [3] [5] = "Mobile Phone repair"; obj [3] [6] = "Mobile Phone repair "; obj [3] [7] = "Optical Fiber Communication"; break; case 4: obj [4] [0] = "section 5 "; obj [4] [1] = "Android experiment"; obj [4] [2] = ""; obj [4] [3] = ""; obj [4] [4] = ""; obj [4] [5] = ""; obj [4] [6] = ""; obj [4] [7] = ""; break; case 5: obj [5] [0] = "Lesson 6 "; obj [5] [1] = "Android experiment"; obj [5] [2] = ""; obj [5] [3] = ""; obj [5] [4] = ""; obj [5] [5] = ""; obj [5] [6] = ""; obj [5] [7] = ""; break; case 6: obj [6] [0] = "Lesson 7 "; obj [6] [1] = "Android experiment"; obj [6] [2] = ""; obj [6] [3] = ""; obj [6] [4] = ""; obj [6] [5] = ""; obj [6] [6] = ""; obj [6] [7] = ""; break; case 7: obj [7] [0] = "Lesson 7 "; obj [7] [1] = ""; obj [7] [2] = ""; obj [7] [3] = ""; obj [7] [4] = ""; obj [7] [5] = ""; obj [7] [6] = ""; obj [7] [7] = ""; break; case 8: obj [8] [0] = "Lesson 8 "; obj [8] [1] = ""; obj [8] [2] = ""; obj [8] [3] = ""; obj [8] [4] = ""; obj [8] [5] = ""; obj [8] [6] = ""; obj [8] [7] = ""; break ;}} JTable table = new JTable (obj, columnNames); TableColumn column = null; int colunms = table. getColumnCount (); for (int I = 0; I <colunms; I ++) {column = table. getColumnModel (). getColumn (I); column. setPreferredWidth (100);} table. setAutoResizeMode (JTable. AUTO_RESIZE_OFF); JScrollPane scroll = new JScrollPane (table); scroll. setSize (300, 50); add (scroll); this. setLocation (450,200); this. setVisible (true); this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); this. pack () ;}public static void main (String [] args) {new KeChengBiaoUI ();}}

Course schedule Interface

5. Complete the Student Score query page (the Code is as follows)

Package com. pag_1; import javax. swing. JFrame; import javax. swing. JScrollPane; import javax. swing. JTable; import javax. swing. table. tableColumn; public class ChengJiBiaoUI extends JFrame {public ChengJiBiaoUI () {intiComponent () ;}// initialize the form component private void intiComponent () {String [] columnNames = {"number of courses ", "Course name", "Credits", "score", "score", "retake "}; // set the name of the JTable column Object [] [] obj = new Object [7] [7]; for (int I = 0; I <7; I ++) {for (int j = 0; j <7; j ++) {switch (j) {case 0: obj [0] [0] = "1 "; obj [0] [1] = "Optical Fiber Communication"; obj [0] [2] = "2"; obj [0] [3] = "1.5 "; obj [0] [4] = "75"; obj [0] [5] = "no"; break; case 1: obj [1] [0] = "2"; obj [1] [1] = "Android"; obj [1] [2] = "2 "; [1] [3] = "1.8"; obj [1] [4] = "5"; obj [1] [5] = "no"; break; case 2: obj [2] [0] = "3"; obj [2] [1] = "Iot"; obj [2] [2] = "1.5 "; [2] [3] = "1.2"; obj [2] [4] = "70"; obj [2] [5] = "no"; break; case 3: obj [3] [0] = "4"; obj [3] [1] = "Electromagnetic Field"; obj [3] [2] = "2 "; obj [3] [3] = "1.6"; obj [3] [4] = "78"; obj [3] [5] = "no"; break; case 4: obj [4] [0] = "5"; obj [4] [1] = "Mobile Phone repair"; obj [4] [2] = "1.0 "; obj [4] [3] = "1.0"; obj [4] [4] = "excellent"; obj [4] [5] = "no"; break; case 5: obj [5] [0] = "6"; obj [5] [1] = "DSP"; obj [5] [2] = "1.0 "; obj [5] [3] = "1.0"; obj [5] [4] = "good"; obj [5] [5] = "no"; break; case 6: obj [6] [0] = "7"; obj [6] [1] = "communication principle experiment "; obj [6] [2] = "1.0"; obj [6] [3] = "1.0"; obj [6] [4] = "good "; obj [6] [5] = "no"; break ;}} JTable table = new JTable (obj, columnNames ); // One Of The JTable construction methods is TableColumn column = null; // set the default width and height of the JTable column int colunms = table. getColumnCount (); for (int I = 0; I <colunms; I ++) {column = table. getColumnModel (). getColumn (I); column. setPreferredWidth (100); // sets the default width of each column to 100} table. setAutoResizeMode (JTable. AUTO_RESIZE_OFF); // set JTable to automatically adjust the list status. Here, JScrollPane scroll = new JScrollPane (table) is disabled; // use JScrollPane to load JTable, in this way, you can view scroll through the scroll bar for columns out of the range. setSize (300, 50); add (scroll); this. setLocation (450,200); this. setVisible (true); this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); this. pack () ;}public static void main (String [] args) {new ChengJiBiaoUI ();}}

Student renewal Table Interface

6. Complete the instructor's Course Management Interface (the Code is as follows)

Package com. pag_1; import javax. swing. JFrame; import javax. swing. JScrollPane; import javax. swing. JTable; import javax. swing. table. tableColumn; public class KeChengGuanLiUI extends JFrame {public KeChengGuanLiUI () {intiComponent ();} private void intiComponent () {String [] columnNames = {"number of courses", "Monday ", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday "}; object [] [] obj = new Object [8] [8]; for (int I = 0; I <8; I ++) {for (int j = 0; j <8; j ++) {switch (j) {case 0: obj [0] [0] = "Lesson 1 "; obj [0] [1] = "lessons available"; obj [0] [2] = ""; obj [0] [3] = ""; obj [0] [4] = "lessons available"; obj [0] [5] = ""; obj [0] [6] = ""; obj [0] [7] = ""; break; case 1: obj [1] [0] = "Lesson 2 "; obj [1] [1] = "lessons available"; obj [1] [2] = ""; obj [1] [3] = ""; obj [1] [4] = "lessons available"; obj [1] [5] = ""; obj [1] [6] = ""; obj [1] [7] = ""; break; case 2: obj [2] [0] = "Lesson 3 "; obj [2] [1] = ""; obj [2] [2] = ""; obj [2] [3] = "lessons available "; obj [2] [4] = ""; obj [2] [5] = ""; obj [2] [6] = ""; obj [2] [7] = ""; break; case 3: obj [3] [0] = "Lesson 4 "; obj [3] [1] = ""; obj [3] [2] = ""; obj [3] [3] = "lessons available "; obj [3] [4] = ""; obj [3] [5] = ""; obj [3] [6] = ""; obj [3] [7] = ""; break; case 4: obj [4] [0] = "section 5"; obj [4] [1] = ""; obj [4] [2] = ""; obj [4] [3] = ""; obj [4] [4] = ""; obj [4] [5] = ""; obj [4] [6] = ""; obj [4] [7] = ""; break; case 5: obj [5] [0] = "Lesson 6"; obj [5] [1] = ""; obj [5] [2] = "meeting "; obj [5] [3] = ""; obj [5] [4] = ""; obj [5] [5] = ""; obj [5] [6] = ""; obj [5] [7] = ""; break; case 6: obj [6] [0] = "Lesson 7"; obj [6] [1] = ""; obj [6] [2] = "lessons available "; obj [6] [3] = ""; obj [6] [4] = "meeting"; obj [6] [5] = ""; obj [6] [6] = ""; obj [6] [7] = ""; break; case 7: obj [7] [0] = "Lesson 8"; obj [7] [1] = ""; obj [7] [2] = "lessons available "; obj [7] [3] = ""; obj [7] [4] = ""; obj [7] [5] = ""; obj [7] [6] = ""; obj [7] [7] = ""; break ;}} JTable table = new JTable (obj, columnNames ); tableColumn column = null; int colunms = table. getColumnCount (); for (int I = 0; I <colunms; I ++) {column = table. getColumnModel (). getColumn (I); column. setPreferredWidth (100);} table. setAutoResizeMode (JTable. AUTO_RESIZE_OFF); JScrollPane scroll = new JScrollPane (table); scroll. setSize (300, 50); add (scroll); this. setLocation (450,200); this. setVisible (true); this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); this. pack () ;}public static void main (String [] args) {new KeChengGuanLiUI ();}}

Instructor course management

7. Complete the student list page on the instructor page (the Code is as follows)

Package com. pag_1; import javax. swing. JFrame; import javax. swing. JScrollPane; import javax. swing. JTable; import javax. swing. table. tableColumn; public class XueShengMingDanUI extends JFrame {public XueShengMingDanUI () {intiComponent () ;}// initialize the form component private void intiComponent () {// set the name of the JTable column String [] columnNames = {"student ID", "name", "Major", "class "}; object [] [] obj = new Object [7] [7]; for (int I = 0; I <7; I ++) {for (int j = 0; j <7; j ++) {switch (j) {case 0: obj [0] [0] = "14140301 "; obj [0] [1] = "Wang Xiaoming"; obj [0] [2] = "Communication Engineering"; obj [0] [3] = "2"; break; case 1: obj [1] [0] = "14140302"; obj [1] [1] = "Wang Lei"; obj [1] [2] = "Communication Engineering "; obj [1] [3] = "2"; break; case 2: obj [2] [0] = "14140303 "; obj [2] [1] = "Li Fang"; obj [2] [2] = "Communication Engineering"; obj [2] [3] = "2"; break; case 3: obj [3] [0] = "14140304"; obj [3] [1] = "zhangsan"; obj [3] [2] = "Communication Engineering "; obj [3] [2] = "2"; break; case 4: obj [4] [0] = "14140305 "; obj [4] [1] = ""; obj [4] [2] = "Communication Engineering"; obj [4] [3] = "2"; break; case 5: obj [5] [0] = "14140306"; obj [5] [1] = "Wenyu"; obj [5] [2] = "Communication Engineering "; obj [5] [3] = "2"; break; case 6: obj [6] [0] = "14140307 "; obj [6] [1] = "Wang Fei"; obj [6] [2] = "Communication Engineering"; obj [6] [3] = "2 "; break ;}} JTable table = new JTable (obj, columnNames); // a construction method of JTable TableColumn column = null; // set the default width and height of the JTable column. int colunms = table. getColumnCount (); for (int I = 0; I <colunms; I ++) {column = table. getColumnModel (). getColumn (I); column. setPreferredWidth (100); // sets the default width of each column to 100} table. setAutoResizeMode (JTable. AUTO_RESIZE_OFF); // set JTable to automatically adjust the list status. Here, JScrollPane scroll = new JScrollPane (table) is disabled; // use JScrollPane to load JTable, in this way, you can view scroll through the scroll bar for columns out of the range. setSize (300, 50); add (scroll); this. setLocation (450,200); this. setVisible (true); this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); this. pack () ;}public static void main (String [] args) {new XueShengMingDanUI ();}}

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

Related Article

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.