First interface
The previous article of this project wrote how to add a background picture to the GUI interface. Now use the background of the previous article to make the first interface of the project. And I also added various listener functions to the buttons on the interface.
Development tool: ideaIU-2021.1.2
Development environment: jdk15.0.2
Development framework: Spring MVC
picture
This is the operation diagram of the first interface ↓
It adds 8 buttons and the listener function of buttons. The pictures of the buttons are all made by myself. Friends in need can confide in me.
code
Don't say much, just go to the code
util class -- create a page class
As I said in the last article, this project will create many interfaces, so I encapsulate the code for creating the interface into a tool class, which can be called directly if necessary.
package com.ZXF.util; import javax.swing.*; //Create page class public class FrameOpen extends JFrame { public FrameOpen(JFrame frame) { frame.setVisible(true); frame.setResizable(false); frame.setSize(900, 500); //Sets where the window appears frame.setLocation(30, 15); //Set click the close button in the upper right corner of the window to close the program frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } }
code annotation
I have debugged the setLocation position and setSize size of the code. The position and size behind the project are debugged according to the current proportion. Don't change it if it's not necessary, but you can debug it yourself if you have a better idea.
view class - interface class
package com.ZXF.view; import com.ZXF.util.Background; import com.ZXF.util.FrameOpen; import javax.swing.*; import java.awt.*; public class FirstFrame extends JFrame { //Add button component //Propositional logic button JButton j1=new JButton(); //Predicate logic button JButton j2=new JButton(); //aggregate JButton j3=new JButton(); //relationship JButton j4=new JButton(); //function JButton j5=new JButton(); //Algebra JButton j6=new JButton(); //Ring and domain JButton j7=new JButton(); //chart JButton j8=new JButton(); public FirstFrame(){ //Construct an initially invisible window with a specified title JFrame frame = new JFrame("discrete mathematics CAI Software"); Container container = frame.getContentPane(); setJ1(frame); setJ2(frame); setJ3(frame); setJ4(frame); setJ5(frame); setJ6(frame); setJ7(frame); setJ8(frame); container.add(j1); container.add(j2); container.add(j3); container.add(j4); container.add(j5); container.add(j6); container.add(j7); container.add(j8); //The container does not have a layout manager set container.setLayout(null); // Set background picture new Background(frame, container, "Master page background.jpg"); new FrameOpen(frame); } public void setJ1(JFrame frame) { j1.setIcon(new ImageIcon("src\\com\\ZXF\\picture\\propositional logic .png")); j1.setBounds(60,120,150,100); j1.addActionListener(e -> { if (e.getSource()==j1){ // frame.setVisible(false); And dispose can be used together frame.dispose(); new Propositional(); } }); } public void setJ2(JFrame frame) { j2.setIcon(new ImageIcon("src\\com\\ZXF\\picture\\Predicate logic.png")); j2.setBounds(260,120,150,100); j2.addActionListener(e -> { if (e.getSource()==j2){ // frame.setVisible(false); And dispose can be used together frame.dispose(); new Predicate(); } }); } public void setJ3(JFrame frame) { j3.setIcon(new ImageIcon("src\\com\\ZXF\\picture\\aggregate.png")); j3.setBounds(460,120,150,100); j3.addActionListener(e -> { if (e.getSource()==j3){ // frame.setVisible(false); And dispose can be used together frame.dispose(); new Assemble(); } }); } public void setJ4(JFrame frame) { j4.setIcon(new ImageIcon("src\\com\\ZXF\\picture\\relationship.png")); j4.setBounds(660,120,150,100); j4.addActionListener(e -> { if (e.getSource()==j4){ // frame.setVisible(false); And dispose can be used together frame.dispose(); new Relation(); } }); } public void setJ5(JFrame frame) { j5.setIcon(new ImageIcon("src\\com\\ZXF\\picture\\function.png")); j5.setBounds(60,240,150,100); j5.addActionListener(e -> { if (e.getSource()==j5){ //frame.setVisible(false); And dispose can be used together frame.dispose(); new Function(); } }); } public void setJ6(JFrame frame) { j6.setIcon(new ImageIcon("src\\com\\ZXF\\picture\\Algebraic system.png")); j6.setBounds(260,240,150,100); j6.addActionListener(e -> { if (e.getSource()==j6){ //frame.setVisible(false); And dispose can be used together frame.dispose(); new Algebraic(); } }); } public void setJ7(JFrame frame) { j7.setIcon(new ImageIcon("src\\com\\ZXF\\picture\\Ring domain.png")); j7.setBounds(460,240,150,100); j7.addActionListener(e -> { if (e.getSource()==j7){ //frame.setVisible(false); And dispose can be used together frame.dispose(); new Loop(); } }); } public void setJ8(JFrame frame) { j8.setIcon(new ImageIcon("src\\com\\ZXF\\picture\\chart.png")); j8.setBounds(660,240,150,100); j8.addActionListener(e -> { if (e.getSource()==j8){ //frame.setVisible(false); And dispose can be used together frame.dispose(); new Map(); } }); } }
code annotation
The setboundaries in the code are debugged like the setLocation and setSize of the tool class. Don't change them if necessary.
new Background(frame, container, "main page background. jpg");
This one calls the background setting tool class written in the previous article. If you haven't seen it, the link is here: Discrete Mathematics CAI software-1.GUI interface background setting
// frame.setVisible(false); And dispose can be used together frame.dispose();
When you click the button to create a new interface, setVisible() can set the interface visibility, and dispose() is the destroy function to destroy the current interface. The interface using setVisible (false) is still there, but it is not visible, which will occupy memory, so I choose to use dispose().
summary
This is the first interface of the project. The buttons and listeners are all for the next step. I will continue to update later. If you want to receive the follow-up updates first, you can use your hands, click attention and praise. If you have any questions, you can ask them in the comment area or write to me privately. This article can be optimized. I hope the boss can give me advice.