Overview
The Abstract Window Toolkit (AWT) is the foundational windowing toolkit for Java desktop applications. Located in thejava.awt package, AWT provides the basic building blocks for creating graphical user interfaces, including:
- Native platform components (windows, buttons, text fields)
- Graphics rendering and 2D drawing capabilities
- Event handling infrastructure
- Layout management for component positioning
- Color, font, and image support
Core Classes
Component Hierarchy
AWT follows a hierarchical component model:- Component
- Container
- Frame
java.awt.Component
Base class for all AWT visual components. Provides fundamental capabilities for rendering, event handling, and component lifecycle.Key Methods:Paints the component. Override to provide custom rendering.
Sets the size of the component in pixels.
Shows or hides the component.
Registers a listener for component events (moved, resized, shown, hidden).
Graphics and Rendering
Graphics2D API
The Graphics2D class extends Graphics to provide sophisticated control over geometry, coordinate transformations, color management, and text layout. From source (java.awt.Graphics2D:42-46):This Graphics2D class extends the Graphics class to provide more sophisticated control over geometry, coordinate transformations, color management, and text layout. This is the fundamental class for rendering 2-dimensional shapes, text and images on the Java platform.
- Basic Drawing
- Transformations
- Advanced
Event Handling
AWT uses a delegation event model where event listeners are registered with components.Event Listeners
- ActionListener
- MouseListener
- KeyListener
From source (java.awt.event.ActionListener:30-51):
The listener interface for receiving action events. The class that is interested in processing an action event implements this interface, and the object created with that class is registered with a component, using the component’s addActionListener method.
Layout Managers
Layout managers control the positioning and sizing of components within containers.BorderLayout
From source (java.awt.BorderLayout:31-43):A border layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region may contain no more than one component.
FlowLayout
GridLayout
GridBagLayout
Most flexible but complex layout manager:Complete Application Example
See Also
- Swing API Reference - Modern lightweight GUI framework
- java.desktop Module - Complete desktop API module
- Java 2D Graphics Tutorial