14.1-Full Stack Java notes: The GUI in the Java language in the end is God horse ghost? | AWT | Swing

Source: Internet
Author: User

So far, what we've written in Java is basically a console-based program, and one of the main reasons why the Java programming language is so popular is that it supports graphical user interface functionality, the GUI (graphical user Interface).


The GUI (graphical user Interface) is the graphical UI, which is the graphical interface that the application provides to our users, including Windows, menus, toolbars, and other graphical interface elements such as text boxes, buttons, list boxes, dialog boxes, and more. It can make the application look more friendly.


Learning Java GUI programming is mainly to master two packages, namely: java.awt, javax.swing package, we abbreviated it as AWT and swing, these two packages contain the GUI programming need to use the rich class library.


With the limited number of components in the AWT (abstract window Toolkit, Abstraction Windows Toolkit) and the inability to implement all the functions required for GUI programming, swing was created as an awt extension. Not only does swing provide all the functionality that AWT can provide, but it also expands the functionality of AWT with pure Java code, so swing can meet all the requirements of GUI programming, and this chapter will be about Swing's basic space and layout manager.


We need to note that there is also a sub-package that we often use in the java.awt package: Java.awt.event, which provides interfaces and classes for handling the various events that are fired by the AWT components, which we will explain in detail in the next chapter.

We hope that after the content of this chapter to learn, you can do the following points:

1. Understanding GUI programming and AWT packages and their components

2. Understanding the difference between AWT and swing

3, master the commonly used controls

4. Understanding Java Common Layout Manager

5. Write Java graphical applications using simple swing controls


Veteran advice:

The Java language itself is not good at developing desktop programs, so there are very few uses of AWT and swing at work. However, as a basic technology in Java, beginners need to understand a little bit of basic knowledge.


About AWT

The implementation of GUI programming is done by a series of graphical components, which are called controls;

In earlier versions of Java, GUI controls were provided by a standard library called AWT.

In addition to GUI components, AWT also includes other functions to support image painting, processing of cut/Copy type data transfer, and other related operations.


The java.awt package is a Java built-in package that is part of the Java Basic Class library (JFC), which includes the following:

1. A rich set of interface components that facilitate user input.

2. Place the component in the appropriate location in several layout managers.

3. Event-handling model.

4. Graphics and image tools, and more.

5. To use the classes in the package, you must explicitly declare the following statement: Import java.awt.*;

As shown in 1, the architecture diagram for the control class in the java.awt package. As we can see, the parent class of the control class is component, and its direct or indirect subclasses have controls that we are familiar with in the graphical interface, such as Frame (window), button (buttons), label (label), checkbox (check box), TextArea (multiline text box) , TextField (Single-line text box), and so on.

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9E/0E/wKiom1mKsKmQTA2TAAEYxUd-goM713.png "title=" Figure 1.png "alt=" Wkiom1mkskmqta2taaeyxud-gom713.png "/>

About Swing

Swing is a lightweight component developed on the AWT basis, which not only improves the user interface but also requires less system resources than AWT. Swing is a pure Java component that allows all applications to behave the same as the native appearance when running on different platforms.

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9E/0D/wKioL1mKsOPT53HeAAMDeLVj3kQ129.png "title=" Figure 2.png "alt=" Wkiol1mksopt53heaamdelvj3kq129.png "/>

The Javax.swing package contains a series of swing controls that, if you want to use the classes in the package, must explicitly declare the following statement: Import javax.swing.*;


As shown in 2, the architecture diagram for the control class in the Javax.swing package. As we can see, most of the controls under the package inherit from the controls in the java.awt package, such as: JFrame's parent class is frame,jcomponent component, and so on.


The following section explains the code examples for classes and controls that are commonly used in swing programs.



"Full stack Java notes" is a can help you from Zeto long for the full stack of Java Engineer Series of notes. The author is called Mr. G,10 years Java research and development experience, has been in the digital, Aerospace Institute of a Research and development center engaged in software design and research and development work, from small white gradually achieve engineers, senior engineers, architects. Proficient in Java Platform Software development, Master Java EE, familiar with various popular development framework.


The notes contain six parts from shallow into deep:

A-java Introductory Phase

B-Database from beginner to proficient

C-hand Edge mobile front end and web front end

D-j2ee from understanding to combat

E-java Advanced Frame Fine Solution

F-linux and Hadoop

This article is from the "full stack Java Notes" blog, be sure to keep this source http://javanew.blog.51cto.com/12931675/1954799

14.1-Full Stack Java notes: The GUI in the Java language in the end is God horse ghost? | AWT | Swing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.