The differences and similarities between swing and AWT __swing

Source: Internet
Author: User

Swing's development stems from the Model-view-controler (MVC) architecture, an MVC based architecture that allows swing components to be replaced by different data models and views. Swing components are enhancements to an existing Abstract Window Toolkit (AWT) component, but do not have to replace the AWT component completely. Swing simply provides a more powerful user interface component, especially in programs written with swing, which requires the use of basic AWT handling events. Both of these components can be used in the same interface. Swing components include the from buttons, check boxes. Simple controls such as scroll bars and sliders to tools as complex as the Text pane and editor panes.

The AWT is an abbreviation for the abstract window ToolKit, a toolkit that provides an interface to interact with the local graphical interface. There is a one by one correspondence between the graphical functions in AWT and the graphical functions provided by the operating system, which we call peers. That is, when we use AWT to component graphical user interfaces, we are actually leveraging the graphics library provided by the operating system. Because the graphics libraries of different operating systems provide the same functionality, the functionality that exists on one platform may not exist on another platform. To implement the concept of "compile, run everywhere," as the Java language claims, AWT has to implement its platform independence by sacrificing functionality, which means that the graphical capabilities provided by AWT are the intersection of the graphical features provided by various general-purpose operating systems. Because AWT relies on local methods to implement its functionality, we typically refer to the AWT control as a heavyweight control.

Swing is a set of new graphical interface systems built on AWT, providing all the functionality that AWT can provide, and dramatically expanding the functionality of AWT with pure Java code. For example, not all operating systems provide support for tree controls, and Swing uses the basic graphing methods provided in AWT to simulate tree controls. Because Swing controls are implemented with 100% Java code, tree controls designed on one platform can be used on other platforms. Because the local method is not used in swing to implement graphics capabilities, we typically call swing controls a lightweight control.

The fundamental difference between AWT and swing: Swing refers to the "drawn" non-peer user interface class, and AWT refers to the low-level mechanism of a window toolbox such as event handling. AWT is a local method based on C/s + + programs, which run faster, swing is based on the AWT Java program, it runs relatively slow. for an embedded application, the hardware resources of the target platform are often very limited, and the speed of the application is a crucial factor in the project. In this paradox, the simple and efficient AWT is certainly the first choice for embedded Java . In a standard Java application based on PC or workstation, the limitations of hardware resources on the application are often not the key factors in the project, so the use of swing in standard Java is advocated, that is, the application's functionality is implemented by sacrificing speed.

Popular words:

AWT is the Abstract Window Component Toolkit, the earliest Java development package for programming graphics applications.
Swing is a newly developed package that addresses AWT's problems and is based on AWT.

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.