
The Abstract Window Toolkit (AWT) is the source platform-independent window library of the graphical interface (Widget toolkit) of the Java language . AWT is now part of the Java Foundation Classes (JFC), the standard API for implementing a graphical interface in a Java program.
AWT is also the standard GUI library for some Java ME profiles. For example, Connected Device Configuration profiles require Java runtime support on AWT mobile phones .
History
When Sun Microsystems first released Java in 1995, AWT widgets provided a subtle level of abstraction over the main native user interface. For example, creating an AWT flag causes AWT to directly call a lower-level native subroutine, which creates the flag. However, the check box on Microsoft Windows is not exactly the same as the box on Mac OS or on various Unix types. Some developers prefer this model because it provides a high degree of compliance with the basic windowing tools and seamless integration with native applications. In other words, a GUI program written using AWT looks like a native Microsoft Windows application, running on Windows, and at the same time like a native Apple Macintosh application, running on a Mac, etc. However, some developers do not like this model because they prefer their applications to look the same on all platforms.
In J2SE 1.2, AWT widgets have been largely replaced by similar ones from Swing . In addition to providing a richer set of user interface elements, Swing draws its own widgets (using Java 2D to call low-level subroutines of the local graphics subsystem), rather than relying on a high level of operating system user interface module. Swing provides the ability to use either the system's “look and feel” , which uses the native “look and feel” of the platform, or a cross-platform look (“Java Look and Feel”) that looks the same on all platforms. However, Swing uses AWT to interact with the native window system.
Architecture
AWT provides two API levels:
- Common interface between Java and the native system, used for managing windows , events , layout managers . This API is the foundation of Java GUI programming and is also used by Swing and Java 2D . He contains:
- The interface between the native window system and the Java application;
- The core of the interface event handler;
- Some layout managers ;
- Interface to input devices , such as a mouse and keyboard ; and
- Package
java.awt.datatransferfor use with the clipboard and Drag and Drop .
- The basic set of GUI widgets, such as buttons, text boxes (text box) and menus. It also provides the AWT Native Interface , which allows libraries in native code to draw directly onto a
Canvas.
AWT also provides some high-level functionality to applications:
- Access to the notification area on supported systems; and
- Ability to run some desktop applications, such as web browsers and email clients from a Java application.
Neither the AWT nor the Swing are inherently thread-safe . Thus, code that updates the GUI or handles events must be executed in the Event dispatching thread . Failure to do so may result in a deadlock or contention. To solve this problem, the SwingWorker utility class allows applications to execute "heavy" interface event handlers in the event processing flow.
Mixing AWT and Swing components
Starting with Java 6 # Java SE 6 Update 10, mixing Swing components and basic AWT widgets often resulted in unwanted side effects, with the advent of AWT widgets over Swing widgets, regardless of their specific blending order . This problem is explained by the fact that the architecture of rendering two widget toolkits is very different, despite Swing borrowing heavy top-level containers from AWT [1] .
Starting with Java 6 # Java SE 6 Update 12 , it became possible to mix Swing and AWT widgets without problems with the overlay order.
Implementation
Since the AWT is a bridge to the underlying native user interface, its implementation on a new operating system can be a lot of work, mainly for a set of widgets that require developing from scratch native peers for each of the AWT widgets.
Simultaneously with the development of Java, the project Caciocavallo began to be developed. Its purpose is to provide Java APIs based on OpenJDK to facilitate the writing of AWT implementations for new operating systems [2] . To build the interface, Java2D [3] is used . All necessary modifications are included in the JDK starting with version OpenJDK 7 [4] .
See also
- AWT Wikiknig
- Event dispatching thread
- AWT Native Interface (JAWT)
- Swing
- Standard Widget Toolkit
- Swingworker
Notes
- ↑ Fowler, Amy Mixing heavy and light components . Sun Microsystems (1994). The date of circulation is December 17, 2008. Archived May 1, 2012.
- ↑ Torre, Mario FINAL PROPOSAL: Portable GUI backends (2 March 2008). The appeal date is September 7, 2008. Archived May 1, 2012.
- ↑ Kennke, Roman Cacio Swing AWT peers (3 September 2008). The appeal date is April 21, 2013. Archived April 29, 2013.
- ↑ How much has been pushed upstream? openjdk.java.net (September 20, 2009). “ Catch up, you can’t get it,” it’s completely self contained. ". The appeal date is March 7, 2010. Archived May 1, 2012.
Links
- AWT homepage
java.awt(AWT Javadoc API documentation)