Abstract Window Toolkit
Encyclopedia
The Abstract Window Toolkit (AWT) is Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

's original platform-independent windowing
Windowing system
A windowing system is a component of a graphical user interface , and more specifically of a desktop environment, which supports the implementation of window managers, and provides basic support for graphics hardware, pointing devices such as mice, and keyboards...

, graphics, and user-interface widget toolkit
Widget toolkit
In computing, a widget toolkit, widget library, or GUI toolkit is a set of widgets for use in designing applications with graphical user interfaces...

. The AWT is now part of the Java Foundation Classes
Java Foundation Classes
The Java Foundation Classes are a graphical framework for building portable Java-based graphical user interfaces . JFC consists of the Abstract Window Toolkit , Swing and Java 2D. Together, they provide a consistent user interface for Java programs, regardless whether the underlying user interface...

 (JFC) — the standard API
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...

 for providing a graphical user interface
Graphical user interface
In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...

 (GUI) for a Java program.

AWT is also the GUI toolkit for a number of Java ME
Java Platform, Micro Edition
Java Platform, Micro Edition, or Java ME, is a Java platform designed for embedded systems . Target devices range from industrial controls to mobile phones and set-top boxes...

 profiles. For example, Connected Device Configuration
Connected Device Configuration
The Connected Device Configuration is a specification of a framework for Java ME applications describing the basic set of libraries and virtual-machine features that must be present in an implementation. The CDC is combined with one or more profiles to give developers a platform for building...

 profiles require Java runtimes on mobile telephones to support AWT.

History

When Sun Microsystems
Sun Microsystems
Sun Microsystems, Inc. was a company that sold :computers, computer components, :computer software, and :information technology services. Sun was founded on February 24, 1982...

 first released Java in 1995, AWT widgets provided a thin level of abstraction over the underlying native user interface. For example, creating an AWT check box
Check box
In computing, a checkbox is a graphical user interface element that permits the user to make multiple selections from a number of options or to have the user answer yes or no on a simple yes/no question.Normally, checkboxes are shown on...

 would cause AWT directly to call the underlying native subroutine that created a check box. However, a check box on Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 is not exactly the same as a check box on Mac OS
Mac OS
Mac OS is a series of graphical user interface-based operating systems developed by Apple Inc. for their Macintosh line of computer systems. The Macintosh user experience is credited with popularizing the graphical user interface...

 or on the various types of Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

. 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
Java Platform, Standard Edition
Java Platform, Standard Edition or Java SE is a widely used platform for programming in the Java language. It is the Java Platform used to deploy portable applications for general use...

, the AWT's widgets were largely superseded by those of the Swing
Swing (Java)
Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes — an API for providing a graphical user interface for Java programs....

 toolkit. In addition to providing a richer set of UI widgets, Swing draws its own widgets (by using Java 2D
Java 2D
In computing, Java 2D is an API for drawing two-dimensional graphics using the Java programming language. Every Java 2D drawing operation can ultimately be treated as filling a shape using a paint and compositing the result onto the screen....

 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 API
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...

s:
  • A general interface between Java and the native system, used for windowing
    Windowing system
    A windowing system is a component of a graphical user interface , and more specifically of a desktop environment, which supports the implementation of window managers, and provides basic support for graphics hardware, pointing devices such as mice, and keyboards...

    , events
    Event-driven programming
    In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...

    , and layout manager
    Layout manager
    Layout managers are software components used in widget toolkits which have the ability to lay out widgets by their relative positions without using distance units. It is often more natural to define component layouts in this manner than to define their position in pixels or common distance units,...

    s. This API is at the core of Java GUI
    Graphical user interface
    In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...

     programming and is also used by Swing
    Swing (Java)
    Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes — an API for providing a graphical user interface for Java programs....

     and Java 2D
    Java 2D
    In computing, Java 2D is an API for drawing two-dimensional graphics using the Java programming language. Every Java 2D drawing operation can ultimately be treated as filling a shape using a paint and compositing the result onto the screen....

    . It contains:
    • The interface between the native windowing system and the Java application;
    • The core of the GUI event
      Event-driven programming
      In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...

       subsystem;
    • Several layout manager
      Layout manager
      Layout managers are software components used in widget toolkits which have the ability to lay out widgets by their relative positions without using distance units. It is often more natural to define component layouts in this manner than to define their position in pixels or common distance units,...

      s;
    • The interface to input device
      Input device
      In computing, an input device is any peripheral used to provide data and control signals to an information processing system such as a computer or other information appliance...

      s such as mouse
      Mouse (computing)
      In computing, a mouse is a pointing device that functions by detecting two-dimensional motion relative to its supporting surface. Physically, a mouse consists of an object held under one of the user's hands, with one or more buttons...

       and keyboard
      Keyboard (computing)
      In computing, a keyboard is a typewriter-style keyboard, which uses an arrangement of buttons or keys, to act as mechanical levers or electronic switches...

      ; and
    • A package
      Java package
      A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time...

       for use with the Clipboard
      Clipboard (software)
      The clipboard is a software facility that can be used for short-term data storage and/or data transfer between documents or applications, via copy and paste operations...

       and Drag and Drop.

  • A basic set of GUI widgets such as buttons, text boxes, and menus. It also provides the AWT Native Interface
    Java AWT Native Interface
    Java AWT Native Interface is an interface for the Java programming language that enables rendering libraries compiled to native code to draw directly to a Java Abstract Window Toolkit object drawing surface....

    , which enables rendering
    Rendering (computer graphics)
    Rendering is the process of generating an image from a model , by means of computer programs. A scene file contains objects in a strictly defined language or data structure; it would contain geometry, viewpoint, texture, lighting, and shading information as a description of the virtual scene...

     libraries
    Library (computer science)
    In computer science, a library is a collection of resources used to develop software. These may include pre-written code and subroutines, classes, values or type specifications....

     compiled to native code to draw directly to an AWT object
    Object (computer science)
    In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure...

     drawing surface.


AWT also makes some higher level functionality available to applications, such as:
  • Access to the system tray on supporting systems; and
  • The ability to launch some desktop applications such as web browser
    Web browser
    A web browser is a software application for retrieving, presenting, and traversing information resources on the World Wide Web. An information resource is identified by a Uniform Resource Identifier and may be a web page, image, video, or other piece of content...

    s and email clients from a Java application.


Neither AWT nor Swing are inherently thread safe. Therefore, code that updates the GUI or processes events should execute on the Event dispatching thread
Event dispatching thread
The event dispatching thread is a background thread used in Java to process events from the Abstract Window Toolkit graphical user interface event queue. These events are primarily update events that cause user interface components to redraw themselves, or input events from input devices such as...

. Failure to do so may result in a deadlock
Deadlock
A deadlock is a situation where in two or more competing actions are each waiting for the other to finish, and thus neither ever does. It is often seen in a paradox like the "chicken or the egg"...

 or race condition. To address this problem, a utility class called 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
Swing (Java)
Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes — an API for providing a graphical user interface for Java programs....

 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
Z-order
Z-order is an ordering of overlapping two-dimensional objects, such as windows in a graphical user interface , shapes in a vector graphics editor, or objects in a 3D application. One of the features of a typical GUI is that windows may overlap, so that one window hides part or all of another...

. This problem was because the rendering architecture of the two widget toolkits was very different, despite Swing borrowing heavyweight top containers from AWT.

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

Implementation

As the AWT is a bridge to the underlying native user-interface, its implementation on a new operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

 may involve a lot of work, especially if it involves any of the AWT GUI widgets, because each of them requires that its native peers be developed from scratch.

A new project, Caciocavallo, has been created, that provides an OpenJDK
OpenJDK
OpenJDK is a free and open source implementation of the Java programming language. It is the result of an effort Sun Microsystems began in 2006...

-based Java API to ease AWT implementation on new systems. The project has successfully implemented AWT widgets using Java2D. All the necessary core-JDK modifications have since been pushed to OpenJDK 7
OpenJDK
OpenJDK is a free and open source implementation of the Java programming language. It is the result of an effort Sun Microsystems began in 2006...

, which means that Java can now be used on a graphics stack other than one of those provided by the official JDK (X Window System
X Window System
The X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...

, OpenGL
OpenGL
OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...

 or DirectX
DirectX
Microsoft DirectX is a collection of application programming interfaces for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with Direct, such as Direct3D, DirectDraw, DirectMusic, DirectPlay,...

), by including an external library and setting some system properties. A DirectFB
DirectFB
DirectFB stands for Direct Frame Buffer. It is a software library for GNU/Linux/Unix-based operating systems with a small memory footprint that provides graphics acceleration, input device handling and abstraction layer, and integrated windowing system with support for translucent windows and...

 backend for Caciocavallo is under development, as is an HTML5 backend; the aim is to deploy existing Swing applications—without Java support—as ordinary web applications running on a web server.

See also

  • Wikibook about AWT
  • Event dispatching thread
    Event dispatching thread
    The event dispatching thread is a background thread used in Java to process events from the Abstract Window Toolkit graphical user interface event queue. These events are primarily update events that cause user interface components to redraw themselves, or input events from input devices such as...

  • AWT Native Interface (JAWT)
    Java AWT Native Interface
    Java AWT Native Interface is an interface for the Java programming language that enables rendering libraries compiled to native code to draw directly to a Java Abstract Window Toolkit object drawing surface....

  • Swing
    Swing (Java)
    Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes — an API for providing a graphical user interface for Java programs....

  • Standard Widget Toolkit
    Standard Widget Toolkit
    The Standard Widget Toolkit is a graphical widget toolkit for use with the Java platform. It was originally developed by IBM and is now maintained by the Eclipse Foundation in tandem with the Eclipse IDE...

  • SwingWorker
    SwingWorker
    SwingWorker is a popular utility class developed by Sun Microsystems for the Swing library of the Java programming language. enables proper use of the event dispatching thread...


External links

  • AWT homepage (AWT Javadoc
    Javadoc
    Javadoc is a documentation generator from Sun Microsystems for generating API documentation in HTML format from Java source code.The "doc comments" format used by Javadoc is the de facto industry standard for documenting Java classes. Some IDEs, such as Netbeans and Eclipse automatically generate...

    API documentation)
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK