The relationship between AWT and swing in Java and their differences

Source: Internet
Author: User

To put it simply:

AWT is the Abstract Window component toolkit and the earliest Java application used to write graphics programs.Program.
Swing is a newly developed package to solve AWT problems. It is based on AWT.

Specifically:

AWT is the abbreviation of Abstract Window Toolkit (Abstract Window Toolkit). This toolkit provides a set of interfaces for interacting with the local graphic interface. The graphic functions in AWT have a one-to-one relationship with the graphic functions provided by the operating system. We call them peers. That is to say, when we use awt to construct a graphical user interface, we actually use the graphic library provided by the operating system. Because the graphic libraries of different operating systems provide different functions, functions on one platform may not exist on another platform. To implement the concept of "one-time compilation and running everywhere" declared by the Java language, AWT has to sacrifice its functions to achieve platform independence. That is to say, the graphic functions provided by AWT are the intersection of the graphic functions provided by various general operating systems. Since AWT relies on local methods to implement its functions, we usually call the AWT control a heavyweight control.

Swing is a New GUI system built on the basis of AWT. It provides all the functions that AWT can provide and uses pure JavaCodeThe AWT function is greatly expanded. For example, not all operating systems provide support for tree controls. Swing uses the basic plotting method provided in awt to simulate tree controls. Since swing controls are implemented using 100% Java code, tree controls designed on one platform can be used on other platforms. Since the local method is not used in swing to implement graphical functions, we usually call the swing control a lightweight control.

Differences Between AWT and swing: AWT is a local-Based C/C ++ program that runs fast. Swing is an AWT-based Java program, it runs slowly. For an embedded application, the hardware resources of the target platform are often very limited, and the running speed of the application is a crucial factor in the project. In this case, the simple and efficient AWT has certainly become the first choice for embedded Java. In common standard Java applications based on PCs or workstations, the restrictions imposed by hardware resources on applications are often not a key factor in the project. Therefore, swing is recommended in Java Standard Edition, that is, the application functions are achieved at the expense of speed.

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.