Jump to content

Abstract Window Toolkit

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 195.243.113.249 (talk) at 17:55, 27 November 2009 (→‎History: missing word). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Windows form with some AWT examples

The Abstract Window Toolkit (AWT) is Java's original platform-independent windowing, graphics, and user-interface widget toolkit. The AWT is now part of the Java Foundation Classes (JFC) — the standard API for providing a graphical user interface (GUI) for a Java program.

AWT is also the GUI toolkit for a number of Java ME profiles. For example, Connected Device Configuration profiles require Java runtimes on mobile telephones to support AWT.

History

When Sun Microsystems first released Java in 1995, bit AWT widgets provided a thin level of abstraction over the underlying native user interface. For example, creating an AWT check box would cause AWT directly to call the underlying native subroutine that created a check box. However, a check box on Microsoft Windows is not exactly the same as a check box on Mac OS or on the various types of UNIX. Some application developers prefer this model because it provides a high degree of fidelity to the underlying native windowing toolkit and seamless integration with native applications. In other words, a GUI program written using AWT looks like a native Microsoft Windows application when run on Windows, but the same program looks like a native Apple Macintosh application when run on a Mac, etc. However, some application developers dislike this model because they prefer their applications to look exactly the same on every platform.

In J2SE 1.2, the AWT's widgets were largely superseded by those of the Swing toolkit. In addition to providing a richer set of UI widgets, Swing draws its own widgets (by using Java 2D to call into low-level subroutines in the local graphics subsystem) instead of relying on the operating system's high-level user interface module. Swing provides the option of using either a System "look and feel" which uses the native platform's look and feel, or a cross-platform look and feel (the "Java Look and Feel") that looks the same on all platforms. However, Swing relies on AWT for its interface to the native windowing system.

Architecture

The AWT provides two levels of APIs:

AWT also provide some miscellaneous useful utilities, that can also be used by Swing, such as:

Neither AWT nor Swing are inherently thread safe. Therefore, code that updates the GUI or processes events should execute on the Event dispatching thread. Failure to do so may result in a deadlock or race condition. To address this problem, a utility class called SwingWorker allows applications to perform time-consuming tasks following user-interaction events in the event dispatching thread.

Mixing AWT and Swing components

Prior to Java 6 Update 12, mixing Swing components and basic AWT widgets often resulted in undesired side effects, with AWT widgets appearing on top of the Swing widgets regardless of their defined z-order. This problem was due to the fact that the rendering architecture of the two widget toolkits was very different, despite Swing borrowing heavyweight top containers from AWT[1].

Starting in Java 6 Update 12, it is possible to mix Swing and AWT widgets without having z-order problems[2][3].

Implementation

As AWT is a bridge to the underlying native user interface, its implementation on a new operating system may involve a lot of work, especially for the set of AWT GUI widgets, which require the development ab initio of native peers for each of the AWT widgets.

Since the opening of Java, a project called Caciocavallo has been created. It aims to provide a Java API based on the OpenJDK to ease AWT implementation on new systems.[4]. The project has successfully experimented the implementation of AWT widgets using Java2D[5]

See also

References

  1. ^ Fowler, Amy (1994). "Mixing heavy and light components". Sun Microsystems. Retrieved 17 December 2008.
  2. ^ Geertjan, Wielenga (16 December 2008). "A Farewell to Heavyweight/Lightweight Conflicts". Retrieved 17 December 2008.
  3. ^ "Bug/RFE fixed in current JDK 6u12 build". Sun Microsystems. 12 December 2008. Retrieved 17 December 2008.
  4. ^ Torre, Mario (2 March 2008). "FINAL PROPOSAL: Portable GUI backends". Retrieved 7 September 2008.
  5. ^ Kennke, Roman (3 September 2008). "Cacio Swing AWT peers". Retrieved 7 September 2008.

This article is based on material taken from the Free On-line Dictionary of Computing prior to 1 November 2008 and incorporated under the "relicensing" terms of the GFDL, version 1.3 or later.