1. Definition
The full name of GUI is Graphical User Interface, that is, graphical user interface. JDK provides two packages, AWT and Swing, for the design and development of GUI programs.
1.java .awt abstract Window Toolkit (Abstract Window Toolkit), which is an early version of java, has limited types of components and needs to call local system methods to implement functions. It is heavyweight and somewhat platform-dependent.
2.javax.SWing is a graphical user interface system established by Sun Company on the basis of AWT. It provides more components and is completely implemented in Java, which enhances portability and is lightweight. magnitude.
SWing is equivalent to an upgraded version of AWT, which solves the problem of cross-platform operation. However, it does not mean that AWT has been completely eliminated. It is the foundation, and it is still important to understand its performance.
2. AWT class hierarchy
import java.awt.Frame;public class Test19 {public static void main(String[] args) { demo(); }static void demo() { Frame f = new Frame("这是我做的第一个窗口"); f.setSize(400, 400); f.setLocation(40, 60);// 左上角的坐标System.out.println("運行成功");// 验证程序是否被执行了 } }If you do the above code, judging from the console results, the program has not hung up and has been executed. The desired dialog box just doesn't appear.
f.setVisible(true);
import java.awt.Frame;public class Test19 {public static void main(String[] args) { demo(); }static void demo() { Frame f = new Frame("这是我做的第一个窗口"); f.setSize(400, 400); f.setLocation(40, 60);// 左上角的坐标 f.setVisible(true);//使得窗口可见 System.out.println("運行成功");// 验证程序是否被执行了 } }
import java.awt.Button;import java.awt.Frame;public class Test19 {public static void main(String[] args) { demo(); }static void demo() { Frame f = new Frame("这是我做的第一个窗口"); f.setSize(400, 400); f.setLocation(40, 60);// 左上角的坐标f.setVisible(true);// 使得窗口可见Button b = new Button("按钮");// 需要导包f.add(b);// 添加该按钮System.out.println("運行成功");// 验证程序是否被执行了 } }Execution results: (Note that if there is a button, the button will fill the border by default when the size and position are not set)
Summary:
Many GUI components can be divided into two major categories according to their functions, basic components and containers . Basic components: buttons, text boxes, etc., cannot accommodate other components. Container: can accommodate other components, such as windows, dialog boxes, etc. All containers are direct or indirect subclasses of java.awt.Container (the Frame above is a container)Attachment, thoughts:
The above program ends when it is executed to System.out.println("Run successfully"); In fact, the main function ends at this time. But the window is still there. We can even do it. Then there must be other foreground threads running. It can be understood that when Frame is created, another thread is started.The above is the detailed content of GUI programming in Java. For more information, please follow other related articles on the PHP Chinese website!

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

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

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

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]

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


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool