Introduction to the AWT
The Java "Abstract Window Toolkit" (AWT) is both powerful and flexible. The AWT provides many classes for programmers to use. It is your connection between your application and the GUI components. It is a Java package that can be used in any Java program by importing "java.awt.*" using the "import" keyword.
The AWT hierarchy
AWT includes the following classes:
- CardLayout
- GridLayout
- BorderLayout
- FlowLayout
- GridBagLayout
- CheckboxGroup
- component
- List
- Color
- Label
- Scrollbar
- Dimension
- Event
- FontMetrics
- FileDialog
- Font
- GridBagConstraints
- Graphics
- Insets
- Image
- Point
- Rectangle
- Polygon
- Toolkit
Interfaces
AWT includes the following interfaces:
Components and Containers:
There are two user-interface classes in the AWT to focus on: "Containers" and "Components".
Containers
Containers handle events that occurr to the Components. Containers (Windows, Frames, Dialogs and Panels) can contain components, thus can be added to Containers.
A quick summary of container methods:
- getComponents()
- remove(Component)
- add(Component)
- setLayout(LayoutManager)
- getLayout()
- add(String, Component)
All of the methods in a Component can be used in a Container. Every Container is a Component since it is derived from a Component, thus it used and behaves like a Component.
Components
Components are Buttons, TextAreas, Scrollbars, etc. In other words the visible UI controls that the user interacts with, all of which have been added to a Container.
A quick summary of the common methods is the following:
- setBackground(Color)
- getBackground()
- setFont(Font)
- getFont()
- mouseDown(Event, int, int)
- show()
- update(Graphics)
- move(int, int)
- resize(int, int)
- paint(Graphics)
Layouts
A Layout is used to set an attractive view to our frame or window. Since the LayoutManager class is abstract, we can't use it directly. We must make a sub class of that and override all its functions and attributes.
There are various layouts, but the ones pre-defined are the following.
BorderLayout: This scheme lays out the comonent in the following 5 ways:


Join the conversation! Your thoughts help the community grow.