search
HomeJavajavaTutorialRegain 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PM

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PM

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PM

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PM

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

How does Java's classloading mechanism work, including different classloaders and their delegation models?How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PM

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor