Home >Java >javaTutorial >Regain the basics of Java (19): Summary of simple use of GUI
Regain the basics of java (Nineteen): Summary of simple use of GUI
1. Professional terminology
UI User Interface User Interface 2. CLI Command Line
3. GUI Graphical Interface
4. QQ, WPS, etc. we usually use Many software have GUI, but background service programs do not have UI
2. Java GUI system
java.awt Heavyweight
2. javax.swing lightweight
3. The form and the labels, text boxes, buttons, etc. on the form can be called components or controls
4. GUI API structure chart
a. Component is the top-level parent class component
b. Divided into two groups: container ordinary component
3 , JFrame class
Form with title bar and form button
2. Construction method JFrame() JFrame( String title)
3. Function method setDefaultCloseOperation()
0: means nothing will be done when the close button is clicked
1: means the form will be hidden when the close button is clicked Default
2: Indicates closing the form and ending the program at the same time
4. Commonly used components
For any component, Both contain two parts: properties and actions (events)
2. Single-line text box JTextField class Label JLable class Password box JPasswordField class Button JButton class Text area JTextArea class
3. Functional methods
public String getText() public void setText(String text) public void setSize(int width, int height) public void setLocation(int x , int y)
5. Layout management
Components need to be placed in the form to be displayed and used, which involves layout issues
2. layout
3. Two categories: absolute positioning Using Java’s built-in layout manager
4. Manual absolute positioning
a. Use the upper left corner of the form as the far point
b.setLocation() method
6. Use Java’s built-in layout manager
A class that can implement a certain layout
2. FlowLayout class: flow layout from left to right
3. BorderLayout class : Divide a form into East, West, North, South, Center by default
4. GridLayout class: Grid layout Divide a form into several rows and columns
7. Event listening mechanism
Bind the function to the interface
2. Event driven Process driven
3. Event itself: Mouse-related events Keyboard-related events Form-related events User operations on the interface Class
4. Event source: Which component the event occurs on Class
5. Listener: Yes An interface, specifically using the implementation class of the interface
6. We need to customize a listener class, implement the xxxListener interface, and then rewrite the relevant methods to call the event source.addxxxListener(new listener class( )) method for binding
8. Dialog box
The dialog box is also a component like the button, JOptionPane class
2. public static void showMessageDialog(Component parentComponent, Object message)
9. Adapter design pattern
1. Adapter Adapter2. Implement The relationship is converted into an inheritance relationship, and the empty implementation class of that interface is called the adapter class
10. Use the WindowBuilder plug-in to achieve visual development
The above is the summary of Regaining the Basics of Java (Nineteen): Simple Use of GUI. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!