5.1 Overview of the AWT

AWT stands for Abstract Window Toolkit. It is a Java package that can be imported as java.awt.* and that consists of platform-independent windowing, graphics, and user interface tools for programmers to use when building up applets and/or stand-alone Java applications.

The classes of the java.awt package can be rougly divided into:

Graphics tools

The Graphics class is the most important one and defines methods for line and text drawing and image painting. Image processing is supported by the Image class. The classes Point, Rectangle and Polygon contain graphics primitives for points, rectangles, and polygons, respectively. Other classes like Font and Color define details of the graphical display of components.

GUI components

Component and MenuComponent are the root classes. Their subclasses represent visual elements of a graphical user interface. Component is an abstract class in Java, so that you can only create objects belonging to its subclasses. Subclasses that represent basic GUI components are: Button, ScrollBar, TextField, Label, CheckBox, Canvas, and so on.

The Container class is a special subclass of Component: it is a type of component that can contain other components and arranges them visually. The Container class, like Component is an abstract class. It has two direct subclasses:

The most important example of a Panel is an Applet. An Applet does not exist independently: a Web browser or appletviewer is needed to display it. A Panel, like an Applet does not stand on its own: a Panel must be contained inside something else, either a Window, another Panel, or - in case of an Applet - in a Web page.

A Window represents an independent top-level window that is not contained in any other component. Java distinguishes two kinds of windows:

The MenuComponent class provides all means to define menu bars and their elements.


The interface LayoutManager declares methods of classes that control the layout of components within containers. Predefined layouts are:

Event Dispatcher

The Event class is the most important one and it contains public instance variables for use when handling GUI events and actions. The actual handling of events and actions is taken care of by the methods handleEvent and action and by all mouse and key related methods of the Component class, which is the root in the hierarchy of GUI components.

Implementation Specifications

When building up a user interface, you should not deal with the platform-specific details, but instead focus on the generic behavior and design of your interface. Let the developers of browsers and appletviewers take care of how GUI components such as buttons, scrollbars, and so on, look like on the screen. The curious reader is referred to a brief sketch of how the platform implementation of GUI components works.

The following diagram is a subgraph of the complete AWT hierarchy and it shows commonly used classes from the AWT package. The interface LayoutManager and its role in the hierarchy is displayed by dotted lines. The classes Object and Applet are not actually part of the AWT package. They belong to the java.lang and java.applet package, respectively, but they have been included in the diagram to show their position in the total class hierarchy relative to the classes in the java.awt package.

The way you use the AWT to build up a user interface is closely related to the AWT structure as descibed above: components (buttons, scrollbars, ...) are added to and then laid out by layout managers in containers (frames, dialogs, panels). The GUI components, layout managers, and graphics tools determine for the most part the outlook of the user interface. The event and action handling finally gives meaning to the components of the user interface.

Practical examples in this chapter and subsequent chapters shall illustrate the use of the AWT package for creating graphical user interfaces.