Introduction to AWT and Applets · Introduction to Java Programming

AWT Components

Watch lectures

AWT Components

1. What Is AWT? (beginner)

AWT (Abstract Window Toolkit) = Java's first GUI kit (java.awt): windows, buttons, text boxes drawn by OS (native look!). Old but exam-heavy; Swing (later) builds on it!

2. Component Map (exam list!)

import java.awt.*;
Frame f = new Frame("Hi");       // window!
Button b = new Button("Click");  // button!
Label l = new Label("Name:");    // text label!
TextField t = new TextField(20); // one-line input!
TextArea ta = new TextArea(5, 20); // multi-line!
Checkbox c = new Checkbox("veg"); // tick!
Choice ch = new Choice(); ch.add("tea"); // dropdown!
List li = new List(); li.add("a"); // scroll list!
f.add(b); f.add(l); // place (layout decides WHERE — next!)

Hierarchy: Component → Container (holds!) → Frame/Panel/Dialog (windows!).

3. Beginner Full Window (memorize skeleton!)

import java.awt.*;
public class Win {
    public static void main(String[] args) {
        Frame f = new Frame("My Win");
        f.add(new Button("OK"));
        f.setSize(300, 200);
        f.setLayout(new FlowLayout()); // simple line layout!
        f.setVisible(true); // show! (default hidden!)
    }
}

4. Traps

  • setVisible(true) forgotten → invisible window (most common!).
  • setSize needed (else 0×0 dot!).
  • AWT heavyweight (OS peers) vs Swing lightweight (Java-drawn — faster, prettier!).

5. Exam Points

  • Component list + window program — 5-7 marks, very frequent.
  • Hierarchy + setVisible/setSize — 3 marks, frequent.
AI LearningWeb Platform

Coursify — Personal AI Course Generator

Struggling with a difficult subject or concept? Turn any engineering topic into a structured course with interactive lessons, quizzes, and research-backed explanations.

← All Introduction to Java Programming modules