What is swing? What are its advantages over AWT? -

Source: Internet
Author: User

Features of Java swing components:

1. The implementation of swing is a small GUI framework, which has no basic platform dependencies, but is dependent on AWT implementations.

2. The javax. Swing. jcomponent class is the base class of all swing components.

3. The objective of the swing model is to follow the Model-View-controller architecture. The model encapsulates the underlying representation of data and status.

4. The javax. Swing. plaf package provides an interface and many abstract classes to define the pluggable appearance framework. The default appearance is implemented by the class in the javax. Swing. plaf. Basic Package.

 

Swing is a fully self-painted control.
SWT checks whether the platform has any controls in advance. If yes, it uses the platform instead of simulating it on its own.
AWT directly uses the platform. If the platform does not exist, it cannot be used.
SWT focuses on the advantages of AWT river swing

I personally think that swing is suitable for developing graphics and images.
SWT is developed in cooperation with common GUI

 

AWT (Abstract Window Toolkit) is the basis for Java GUI program development. It has the following characteristics: the components (buttons, etc.) in the window are heavyweight components related to the operating system peer components, so it is not flexible enough. At the same time, it was designed to be used in the applet.

Swing is based on AWT. Except for top-level components, it is heavyweight. Other components (such as buttons and input boxes) and layout are lightweight and irrelevant to the operating system. Therefore, it has its own look and feel.

SWT (Standard Widget Toolkit) is another Java-based GUI programming interface in eclipse. Eclipse is based on this.

 

When we started using the swing library, we noticed that it had taken a huge step forward in technology. The swing component is Bean, so they can be used in any bean development environment. Swing provides a complete set of UI components. Due to the speed, all components are very small (no "heavyweight" component is used), and swing is compiled in Java for convenience.

The most important thing is that we want swing to be called "orthogonal use"; once we adopt this common approach to libraries, we can apply them anywhere. This is mainly because of bean naming rules. Most of the time I write these program examples, I can guess the method name and spell it correctly for the first time without looking for anything. This is undoubtedly a proof of the quality of the excellent library design. In addition, We can insert components extensively into other components and events will work normally.

Keyboard operations are automatically supported-we can use a swing application without the mouse, but we have to do some additional programming work (the old AWT requires some terrible code to support keyboard operations ). Scroll is supported effortlessly-we simply add our component to a jscrollpane and add it to our form. Other features, such as a tooltip, can be executed only by a single line of code.

Swing also supports things called "pluggable appearances and effects, this means that the UI can be dynamically changed on different platforms and operating systems to meet user expectations. It can even create our own appearances and effects.

AWT is the basis of swing. The main reason for swing is that AWT cannot meet the development needs of graphical user interfaces. AWT was designed to support simple user interfaces for developing small applications. For example, AWT lacks clipboard, printing support, keyboard navigation, and other features, and the original AWT does not even include basic elements such as pop-up menus or scrolling panes.

In addition, AWT has serious defects. People make AWT adapt to the inherited, highly scalable event model, and the architecture based on the same body has become a fatal weakness.
With the development of swing, almost all swing components are lightweight components. Compared with weight components, there is no local peer-to-peer component, unlike weight components that need to be drawn in their own local opaque forms, lightweight components are drawn in their own weight component windows.

Swing is implemented by 100% pure Java, and the swing component is a lightweight (light-weight) component implemented by Java. It does not have local code and does not rely on the support of the operating system, this is the biggest difference between it and the AWT component. Since the AWT component is implemented through peer implementation related to a specific platform, swing is more practical than the AWT component. Swing performs the same on different platforms and has the ability to provide other features not supported by the local window system.

Swing adopts a MVC design paradigm, namely, "Model-View-controller", where the model is used to save the content and the view is used to display the content, the controller is used to control user input.

In the AWT component, because the peering class controlling the component appearance is related to the specific platform, the AWT component always has only the appearance related to the local machine. Swing enables programs to run on a platform with different appearances. You can select the desired appearance.

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.