java--'s knowledge of swing, AWT and SWT

Source: Internet
Author: User

Understanding of Swing, AWT, and SWT

Summary: Now that Java provides graphical GUI development tools beyond swing, what is the difference between them? This paper mainly analyzes the differences between SWING,AWT and SWT.

  1, three of the overview:

The AWT (Abstract Window Toolkit) is a set of graphical user interface Gui (Interface) Toolsets provided by the API for Java programs, based on a peer. AWT can be used in Java applets and applications. It supports graphical user interface programming functions including: UI components, event processing models, graphics and image tools, including shapes, colors, and font classes; Layout Manager for flexible window layouts independent of the size and screen resolution of a particular window; Data transfer class, You can cut and paste by using the Clipboard on your local platform.

SWT ("Standard Widget Toolkit", a toolkit originally developed by IBM, is now maintained by the Eclipse Foundation. ) is a platform-independent, and is based on a peer implementation, can be separated from the Eclipse framework of the graphical components, using JNI technology to provide the same user interface with the native system component of the look and feel, good operational efficiency, stable platform performance. A basic component of an SWT application is the display screen, the command interface (the shell, which enables the command to enter and make the operation Initialize), and the Widgets (Widgets). Display is responsible for managing the event loop and controlling communication between the UI thread and other threads. A shell is a window that is managed by the operating system Window manager in an application. Each SWT application requires at least one display and a shell instance greater than or equal to 1.

Swing is based on the AWT architecture, allowing changes in the look and feel of each component in the program without changing the volume of program code. The introduction of support for replaceable look-and-feel technology allows swing components to emulate the appearance of native components while preserving the benefits of platform independence.

2, the difference between the three

AWT, SWTT all rely on the underlying platform, all based on peer implementation, on different operating systems developed on the program display is not the same, SWT provides a richer set of components than AWT, and swing on the underlying platform is very little, so give different users a sense of consistency, but also has a rich, A convenient collection of user interface elements. Since both AWT and SWT hold references to local components, they must release these references in the correct manner to avoid memory leaks and JVM crashes. AWT gives the majority of resource management tasks to the system, but this complicates the implementation of AWT. Once it is implemented, developers rarely have the opportunity to make mistakes and crash their programs. And SWT is using another method, it has a rule that is: who creates, who releases. So developers must be careful to explicitly call the Dispose method to release every component and resource that he creates. This simplifies the implementation model of SWT, but puts the developer on the risk of causing the program to crash because of error coding.

AWT only provides controls that all operating systems have, that is, all calls to the local operating system, and swing is just the top-level component of Windows and frames invoking operating system controls, most of which are modeled using Java code; SWT is mostly used by local operating system controls, Some of the controls on other operating systems go through their own drawing. Both swing and SWT use impersonation on the implementation. SWT is a missing component on the analog platform. The difference is that the SWT simulation is more like a simulation of the AWT canvas implementation. The composite class of SWT has its own counterpart in the operating system. It gets all the resource-shaped objects, fonts, and colors that it needs from its peers. It gets all the events directly from the operating system and processes them. However, the swing component does not have a corresponding peer in the operating system. It is just a logical area in a top-level container, which in fact borrows resources from the peer of the top-level container. Swing events are not events generated by the underlying system. They are actually the pseudo-events generated by the AWT event handled by the top-level container. Another difference is that the Z-order system for swing components comes from the AWT components. Swing is based on the AWT architecture, so swing components share a peer with the top-level AWT container. Therefore, the swing component also has the same z-order as the top-level container. Both SWT and AWT components have z-order that differ from the top-level container, usually above the top-level container. Therefore, if the AWT components and swing components are mixed together, swing components may be obscured by the AWT components. When the operating system starts to update the UI, the top-level container and swing components are always drawn before the AWT component. When they are finished drawing, the AWT component overrides where swing might have been drawn. Therefore, the mixing of swing and AWT components is not advocated. If you have a floating swing component such as a menu, the AWT component is likely to obscure the menu.


This article is from the "Mr_computer" blog, make sure to keep this source http://caochun.blog.51cto.com/4497308/1751064

java--'s knowledge of swing, AWT and SWT

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.