The purpose of Java interface design

Source: Internet
Author: User

First, the use of Java interface design:

Javase (Java standard Edition), or Java Standards Edition, is generally understood as the Java Desktop version. Developers can develop rich and powerful desktop applications with graphical interfaces through Javase.

Java's graphical interface toolkit can be used for tool-type software development, management software development, general client development, Bank client software development, Eclipse plug-in development and other directions. In many well-known large-scale software, Java can be seen, such as some versions of Photoshop, mind mapping software, Eclipse, idea development environment and so on.

Developers can also use Java to design some of their own productivity-enhancing tools to help them handle mechanical work.

Why are there multiple sets of GUI toolkits in Java? The best answer is that there is no GUI toolkit to meet all the requirements.

Java's GUI toolkit contains AWT, swing, and SWT, each with its own pros and cons, and developers can choose the right toolkit based on their needs and the target user.

II. Three toolkit for Java GUI design: AWT Swing SWT

AWT (Abstract Windows Toolkit) is the most primitive Java GUI toolkit. The main advantage of AWT is that it becomes a standard configuration on every version of Java technology, including Java implementations in earlier Web browsers, and it is also very stable. This means that we do not need to install the toolkit separately, which can be used in any Java runtime environment.

AWT is a very simple toolkit with limited GUI components, layout managers, and events (such as forms, text labels, buttons, menus, and so on). This is because Sun decided to use a least common denominator (LCD) approach for AWT. Therefore, it only uses the GUI components that are defined for all Java host environments.

Since AWT relies on the host GUI's peer control (where each AWT component has a parallel host control or peer) to implement this GUI, the look and behavior of the GUI will vary on different hosts. This conflicts with Java's "write Once, run everywhere" concept, thus constituting the limitations of AWT.


java Swing is part of the Java Foundation Classes (JFC), which is an attempt to address the shortcomings of AWT. In swing, Sun developed a carefully designed, flexible and powerful GUI toolkit. Swing is built on the AWT component base. Swing uses the AWT event model and support classes, such as colors, images, and graphics. Swing components, layout managers, and events are a broader set of components than AWT provides, fully meeting a variety of development needs.

To overcome the drawbacks of different behaviors on different hosts, swing minimizes host control dependencies. In fact, swing only uses peers for top-level components such as windows and frames. Most of the components (JComponent and its subclasses) are modeled using pure Java code. This means that swing is inherently well-ported across all hosts. Therefore, swing does not usually look like a local program. In fact, it has a lot of appearance, some simulate the appearance of different hosts, and some provide a unique look.

The term that swing uses for peer-based components is heavyweight (heavyweight), and the term used for the emulated component is lightweight (lightweight). In fact, swing can support mixing of heavyweight and lightweight components in a GUI, such as the use of AWT and swing controls in a Jcontainer. In addition, it has the following advantages: 1. Based on MVC structure 2. Programmable appearance 3. Renderer and editor 4. Support for building GUI 5 in any order. Accessibility 6. Support Automatic Destruction 7. is part of standard Java


SWT is also based on a peer, and at this point it is very similar to AWT. It overcomes the LCD problem faced by AWT by defining a set of controls that can be used to build most Office applications or developer tools, and then create mock controls for components that are not provided by a particular host (this is similar to swing), on a host-by-machine basis. For most modern hosts, almost all of the controls are peer-based. This means that the SWT-based GUI has both host appearance and host performance. This avoids most of the problems that are caused by using AWT and swing. A particular host has some low-level feature controls, so SWT provides an expanded (usually simulated) version (usually using "C" as the first letter in the name), which can result in more consistent behavior.

In SWT, a peer is just some special wrapper on a host control. This means that the SWT application is actually a host application that will inevitably inherit all the advantages and disadvantages of the host. This also means that SWT cannot fully implement the "write once, test everywhere" solution. This means that SWT is not as good as swing, but it is outstanding in creating a portable solution. In addition, SWT has the following features: 1. Automatic GUI destruction is not supported 2. Only top-down GUI 3 is supported. Support for JAVA2D is not perfect. 4. Not part of standard Java

Third, how to choose the use of GUI toolkit

Swing is the most flexible and powerful GUI toolkit, so in interface development, swing is preferred, and it is capable of the vast majority of development work.

There is only one occasion that is not suitable for swing: continue to write interfaces on programs developed using SWT, such as developing plug-ins for eclipse (because Eclipse is built on SWT). SWT is incompatible with swing, and they cannot be used in combination.

The purpose of Java interface design

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.