Introduction and comparison of Java GUI:SWT/SWING/AWT

Source: Internet
Author: User
Tags abstract comparison

This article compares the SWT of Eclipse with the Java Swing, Abstract Windows Toolkit (AWT) GUI Toolkit to help developers of new applications choose the appropriate tools from them.

You can learn about the basic features of each toolkit and the pros and cons of using each toolkit through this article.

Brief introduction

Other authors on DeveloperWorks have shown how to migrate well between Swing and SWT (see Resources). The goal of this article is to help you determine which GUI toolkit you choose to use before you start developing your project.

But first we need to figure out a question: Why are there multiple Java™gui toolkits? The best answer is that a toolkit does not meet all of the requirements and has not recently developed a GUI toolkit that meets all the requirements. Each toolkit has its own pros and cons, which allows you to select the appropriate toolkit based on your needs and target users.

Let's learn more about these toolkits below.

AWT Overview

Abstract Windows Toolkit (AWT) is the most original Java GUI toolkit. The main advantage of AWT is that it becomes a standard configuration on every version of Java technology, including the Java implementation in early Web browsers, and it is also very stable. This means that we don't need to install this kit separately, and we can use it in any Java runtime environment, which is exactly what we want.

AWT is a very simple toolkit with limited GUI components, layout managers, and events (see Listing 1, Listing 2, and listing 3). This is because Sun decided to use a minimum common denominator (LCD) method for AWT. Therefore, it will only use GUI components that are defined for all Java host environments. The end result is very unfortunate, some commonly used components, such as tables, trees, progress bar, etc., are not supported. For applications that require more component types, we need to create these components from scratch. This is a big burden.

Listing 1. Basic AWT Class Tree (all in java.awt package, "*" means abstract)

Object checkboxgroup *component Button Canvas CheckBox Choice Container Panel Applet scrollpane Window Dialog Frame Label List textcomponent TextArea TextField menucomponent MenuItem checkboxmenuitem Menu PopupMenu

Note: There are several other AWT components in the other packages, but this is the basic set of components.

Listing 2. AWT provides the following layout manager (all in the java.awt package, "*" to represent the interface)

*layoutmanager flowlayout GridLayout *layoutmanager2 borderlayout cardlayout

Note: There are also some of the AWT layout managers in the other packages, many of which are specifically tailored for the containers they are layout, but this is the basic layout manager set.

Listing 3. AWT provides the following events (mostly in the java.awt.events package)

Object eventobject awtevent actionevent adjustmentevent componentevent containerevent focusevent InputEvent KeyEvent MouseEvent mousewheelevent paintevent windowevent hierarchyevent inputmethodevent InvocationEvent ItemEvent TextEvent

Note: There are other AWT events in the other packages, but this is the basic set of events. These are concrete events that are generated from more general events.

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.