Introduction to AWT

Site Admin · 11 Sep 2026 · 2 views

What is AWT?

The Abstract Window Toolkit (AWT) is Java's original GUI library. It provides windows, buttons, text fields, menus and event handling in a platform-independent way. AWT components have a native look because they use the operating system's widgets through peers.

The Component Hierarchy

Everything derives from Component. Containers like Frame, Panel, Dialog and Applet hold child components such as Button, Label, TextField and TextArea.

AWT class hierarchy

Key Packages

  • java.awt - the core components and containers.
  • java.awt.event - listeners for mouse, keyboard and window events.
  • java.awt.layout? No - layout managers live directly in java.awt.

Hello AWT

import java.awt.*;

public class HelloAwt extends Frame {
    HelloAwt() {
        add(new Label("Hello AWT!"));
        setSize(300, 200);
        setTitle("First Frame");
        setVisible(true);
    }
    public static void main(String[] args) {
        new HelloAwt();
    }
}

This creates a window with a label centered by the default BorderLayout of a Frame.

Key Points

  • AWT draws on native platform widgets, giving an OS look.
  • Component is the base of all controls; Container can hold others.
  • Frames are top-level windows; panels help group components.
Share this post:

Comments (0)

Please login or register to comment.