This article shares the specific code of the Java GUI management system for your reference. The specific content is as follows
1. Complete the main page MainUI 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 { //Define component JButton jb1,jb2,jb3=null; JRadioButton jrb1,jrb2=null; JPanel jp1,jp2,jp3,jp4=null; JTextField jtf=null; JLabel jlb1,jlb2,jlb3=null; JPasswordField jpf=null; ButtonGroup bg=null; //Set username and password final String stu_name="Wang Xiaoming"; final String stu_pwd="1"; final String stu_num="14140301"; final String tea_name="Wang"; 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 listening jb1.addActionListener(this); jb2.addActionListener(this); jb3.addActionListener(this); jrb1=new JRadioButton("Teacher"); jrb2=new JRadioButton("Student"); bg=new ButtonGroup(); bg.add(jrb1); bg.add(jrb2); jrb2.setSelected(true); //The default selection permission of the initial page is student jp1=new JPanel(); jp2=new JPanel(); jp3=new JPanel(); jp4=new JPanel(); jlb1=new JLabel("Username:"); jlb2=new JLabel("Password:"); jlb3=new JLabel("Permission:"); jtf=new JTextField(10); jpf=new JPasswordField(10); //Add to JPanel jp1.add(jlb1); jp1.add(jtf); jp2.add(jlb2); jp2.add(jpf); jp3.add(jlb3); //Add tag jp3.add(jrb1); jp3.add(jrb2); jp4.add(jb1); //Add button jp4.add(jb2); jp4.add(jb3); //Add this.add(jp1); this.add(jp2); this.add(jp3); this.add(jp4); this.setLayout(new GridLayout(4,1)); //Select GridLayout layout manager this.setTitle("Student Score Management System"); this.setSize(300,200); this.setLocation(400, 200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set when closing the window, ensure that the JVM also exits this.setVisible(true); this.setResizable(true); } public void actionPerformed(ActionEvent e) { //Event judgment if(e.getActionCommand()=="Login") { //If the teacher is selected if(jrb1.isSelected()) { tealogin(); //Connect to the teacher's method page}else if(jrb2.isSelected()) //Student is logged in to the system { stulogin(); //Connect to the student's method page} }else if(e.getActionCommand()=="Reset") { clear(); } } //Student login judgment method public void stulogin() { if(stu_name.equals(jtf.getText())&&stu_pwd.equals(jpf.getText()))) { JOptionPane.showMessageDialog(null,"Login successfully!","Prompt 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,"Please enter the username and password!","Prompt message",JOptionPane.WARNING_MESSAGE); }else if(jtf.getText().isEmpty()) { JOptionPane.showMessageDialog(null,"Please enter the username!","Prompt message",JOptionPane.WARNING_MESSAGE); }else if(jpf.getText().isEmpty()) { JOptionPane.showMessageDialog(null,"Please enter the username!","Prompt message",JOptionPane.WARNING_MESSAGE); }else if(jpf.getText().isEmpty()) { JOptionPane.showMessageDialog(null,"Please enter password!","Prompt message",JOptionPane.WARNING_MESSAGE); }else { JOptionPane.showMessageDialog(null,"Username or password is incorrect! /nPlease re-enter","Prompt message",JOptionPane.ERROR_MESSAGE); //Clear the input box clear(); } } //Teacher login judgment method public void tealogin() { if(tea_name.equals(jtf.getText())&&tea_pwd.equals(jpf.getText())) { JOptionPane.showMessageDialog(null,"Login successfully!","Prompt 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,"Please enter the username and password!","Prompt message",JOptionPane.WARNING_MESSAGE); }else if(jtf.getText().isEmpty()) { JOptionPane.showMessageDialog(null,"Please enter the username!","Prompt Message",JOptionPane.WARNING_MESSAGE); }else if(jpf.getText().isEmpty()) { JOptionPane.showMessageDialog(null,"Please enter the password!","Prompt Message",JOptionPane.WARNING_MESSAGE); }else { JOptionPane.showMessageDialog(null,"Unuser name or password! /nPlease re-enter","Prompt Message",JOptionPane.ERROR_MESSAGE); clear(); //Clear the input box} } //Clear the text box and password box public void clear() { jtf.setText(""); jpf.setText(""); } } Run Figure 1
The username and password are as follows:
2. Complete the student interface StuUI. This page has button connections set 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 { //Define component JButton jb1=new JButton(); JButton jb2=new JButton(); JPanel jp1,jp2,jp3,jp4=null; JLabel jlb1,jlb2,jlb3,jlb4,jlb5,jlb6=null; public static void main(String[] args) { StdUI ui=new StdUI(); } //************************************ Event judgment********************************** //Constructor public StdUI() //Cannot declare as void!!! Otherwise, the new interface will not pop up { //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 number:"); jlb3=new JLabel("Latest announcement:"); jlb3.setForeground(Color.red); jlb4=new JLabel("Our school holds student physical test notice"); 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); jp2.add(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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); jb1.addActionListener(this); jb2.addActionListener(this); } public void actionPerformed(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 to enter the user student, and the following student interface will appear. The course sheet and grade query in the interface are two clickable buttons, which will be connected to the next page and then the next step.
3. Complete the teacher interface TerUI. This is the same as the student page. There is a button event on the MainUI page and 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 { //Define component 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("Work number:"); jlb3=new JLabel("Latest Announcement:"); jlb3.setForeground(Color.red); jlb4=new JLabel("Notice of our hospital holding physical test"); 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); jp2.add(jb1); jp2.add(jb2); jp3.add(jlb3); jp3.add(jlb4); this.add(jp1); this.add(jp2); this.add(jp3); this.setLayout(new GridLayout(4,3,50,50)); //Set the layout manager this.setTitle("Student Score Management System"); this.setSize(400,300); this.setLocation(200, 200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); jb1.addActionListener(this); jb2.addActionListener(this);} public void actionPerformed(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 to enter the user teacher, and the following teacher interface will appear. The course management and student list in the interface are two clickable buttons, which will be connected to the next page and then the steps later.
4. Complete the course sheet interface of the student interface (code 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 classes", "Monday", "Tuesday", "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] = "First Lesson"; obj[0][1] = "Fiber Optical Communication"; obj[0][2] = "Electromagnetic Field"; obj[0][3] = "Internet of Things"; obj[0][4] = "DSP Experiment"; obj[0][5] = " "; obj[0][6] = "Mobile Phone Repair"; obj[0][7] = " "; break; case 1: obj[1][0] = "Second Lesson 2"; obj[1][1] = "Fiber Optical Communication"; obj[1][2] = "Electromagnetic Field"; obj[1][3] = "Internet of Things"; 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][3] = " "; obj[3][4] = " "; obj[3][5] = "Mobile phone repair"; obj[3][6] = "Mobile phone repair"; obj[3][7] = "Fiber Optical Communication"; break; case 4: obj[4][0] = "Lesson 5"; obj[4][1] = "Android experiment"; obj[4][2] = " "; obj[4][3] = " "; obj[4][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][6] = " "; obj[6][7] = "; 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][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 columns = 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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); } public static void main(String[] args) { new KeChengBiaoUI(); } }Course Schedule Interface
5. Complete the student's grade query interface (code 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 form component private void intiComponent() { String[] columnNames = { "Number of courses", "Course Name", "Credits", "Grade Points", "Scores", "Make-up Exam" }; //Set the column name of JTable 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] = " fiber optic 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][1] = " Android"; obj[1][2] = " 2"; obj[1][3] = " 1.8"; obj[1][4] = " 5"; obj[1][5] = " No "; break; case 2: obj[2][0] = " 3"; obj[2][1] = " Internet of Things"; obj[2][2] = " 1.5"; obj[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][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][5] = " No "; break; case 6: obj[6][0] = " 7"; obj[6][1] = " Communication Principles 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 JTable's constructors TableColumn column=null; //Set the default width and height of the column of JTable int columns = table.getColumnCount(); for(int i=0;i<colunms;i++) { column = table.getColumnModel().getColumn(i); column.setPreferredWidth(100); //Set the default width of each column to 100 } table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); //Set the status of the JTable automatically adjusts the list, set to turn off JScrollPane scroll = new JScrollPane(table); //Load JTable with JScrollPane, so that columns outside the range can be viewed through the scrollbar by scroll.setSize(300, 50); add(scroll); this.setLocation(450, 200); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); } public static void main(String[] args) { new ChengJiBiaoUI(); } }Student Grade Table Interface
6. Complete the teacher’s course management interface (code 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 classes", "Monday", "Tuesday", "Thursday", "Friday", "Saturday","Sunday" }; 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] = " first lesson"; obj[0][1] = " class with class"; obj[0][2] = " "; obj[0][3] = " "; obj[0][4] = " class with class with class"; obj[0][5] = " "; obj[0][6] = "; obj[0][7] = " "; break; case 1: obj[1][0] = " second lesson"; obj[1][1] = " class with class"; obj[1][2] = ""; obj[1][3] = ""; obj[1][4] = " class with class"; obj[1][5] = " "; obj[1][6] = "; obj[1][7] = " "; break; case 2: obj[2][0] = " class with class with class"; obj[2][1] = ""; obj[2][2][1] = " class with class"; 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][3] = "Lesson 5"; obj[3][4] = " "; obj[3][5] = "; obj[3][6] = ""; obj[3][7] = "; break; case 4: obj[4][0] ="Lesson 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][5][5][7] = " "; break; case 6: obj[6][0] ="Lesson 7"; obj[6][1] = ""; obj[6][2] = " There is a class"; obj[6][3] = " "; obj[6][4] = " Meeting"; obj[6][5] = " "; obj[6][6][6] = " "; obj[6][7] = " "; break; case 7: obj[7][0] =" Lesson 8"; obj[7][1] = ""; obj[7][2] = " There is a class"; 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 columns = 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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); } public static void main(String[] args) { new KeChengGuanLiUI(); } }Teacher Curriculum Management
7. Complete the student list page of the teacher page (code 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 form component private void intiComponent() { // Set the column name of JTable String[] columnNames = { "Student number", "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] = " Zhang San"; obj[3][2] = " Communication Engineering"; obj[3][3] = " 2"; break; case 4: obj[4][0] = " 14140305"; obj[4][1] = " Li Si"; obj[4][2] = " Communication Engineering"; obj[4][3] = " 2"; break; case 5: obj[5][0] = " 14140306"; obj[5][1] = " Wen Yu"; 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); //One of JTable's constructors TableColumn column=null; //Set the default width and height of the column of JTable int columns = table.getColumnCount(); for(int i=0;i<colunms;i++) { column = table.getColumnModel().getColumn(i); column.setPreferredWidth(100); //Set the default width of each column to 100 } table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); //Set the status of JTable's automatic adjustment list, and set to turn off JScrollPane scroll = new JScrollPane(table); //Load JTable with JScrollPane, so that columns outside the range can be viewed by scrollbars by scroll.setSize(300, 50); add(scroll); this.setLocation(450, 200); this.setVisible(true); this.setDefaultCloseOperation(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 to everyone's learning and I hope everyone will support Wulin.com more.