What Is AWT in Java with Example: Beginner’s Guide

Robert Jul 13, 2026

AWT stands for Abstract Window Toolkit, a part of Java that provides a way to build Java applications with a graphical user interface (GUI). It handles all the complexities of displaying GUI components on the screen, allowing developers to focus on coding logic and functionality. In this article, we'll delve into AWT in Java, its components, and the basics of creating a simple GUI.

Java Collection Framework: ArrayList Explained Visually
Java Collection Framework: ArrayList Explained Visually

AWT is a crucial part of Java's original API, and although it's been superseded to some extent by Swing and JavaFX, it's still the foundation upon which these newer GUI libraries are built. Understanding AWT provides a solid foundation for Java GUI programming. Let's start with the basics.

a blue background with the words awt
a blue background with the words awt

AWT Components

The core of AWT is its component model. AWT components can be thought of as building blocks from which Java GUIs are constructed. Several AWT components represent various GUI elements, such as buttons, text fields, panels, and menus.

Abstraction in Java | Abstract Class vs Interface Explained Simply
Abstraction in Java | Abstract Class vs Interface Explained Simply

Let's consider a few of these components:

Button

Java Variables Explained | Local, Static & Instance Variables in Java
Java Variables Explained | Local, Static & Instance Variables in Java

The Button component is used to create clickable buttons in a Java GUI. When a button is clicked, an action is performed, triggering an event. Here's a simple example:

```java import java.awt.*; import java.awt.event.*; public class ButtonExample extends Frame { public ButtonExample() { Button btn = new Button("Click me"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Button clicked!"); } }); add(btn); setSize(200, 200); setVisible(true); } public static void main(String args[]) { new ButtonExample(); } } ```

Label

What is JAVA?
What is JAVA?

The Label component is used to display text or images in a GUI. Labels are typically used to accompany other components, providing context or instructions.

Creating a Simple GUI with AWT

Now, let's combine several AWT components to create a simple GUI. In this example, we'll create a frame with buttons and labels:

☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀

```java import java.awt.*; import java.awt.event.*; public class SimpleGUI extends Frame { public SimpleGUI() { setLayout(new FlowLayout()); Label lbl = new Label("This is a label."); add(lbl); Button btn1 = new Button("Button 1"); add(btn1); Button btn2 = new Button("Button 2"); add(btn2); setSize(300, 200); setVisible(true); } public static void main(String args[]) { new SimpleGUI(); } } ```

Finally, while AWT is essential for understanding Java GUI programming, note that Swing and JavaFX offer more advanced features and better usability. However, understanding AWT first provides valuable insights into how Java GUIs are structured and rendered.

☕ What Is Java? | Simple Guide for Beginners 🚀
☕ What Is Java? | Simple Guide for Beginners 🚀
Inheritance in Java Explained | OOP Concepts for Beginners
Inheritance in Java Explained | OOP Concepts for Beginners
What is Inheritance in Java – 5 Types, Use and Advantages
What is Inheritance in Java – 5 Types, Use and Advantages
Arrays in Java Explained | Java Programming Basics for Beginners
Arrays in Java Explained | Java Programming Basics for Beginners
Abstraction in Java - Learn with its Types and Real-life Examples - TechVidvan
Abstraction in Java - Learn with its Types and Real-life Examples - TechVidvan
Abstract Class Vs Interface in Java
Abstract Class Vs Interface in Java
Java Variables Explained in 60 Seconds | Java Programming Basics
Java Variables Explained in 60 Seconds | Java Programming Basics
Advanced Java (May – 2018) [IDOL: Revised Course | Question Paper]
Advanced Java (May – 2018) [IDOL: Revised Course | Question Paper]
Java TreeMap Infographic for Beginners (2025) - Quipoin
Java TreeMap Infographic for Beginners (2025) - Quipoin
Control Statements in Java | If & If-Else Explained for Beginners
Control Statements in Java | If & If-Else Explained for Beginners
Java Training
Java Training
owasp top 10 web application vulnerabilities
owasp top 10 web application vulnerabilities
If else v/s switch statements in Java | technical-arbaab
If else v/s switch statements in Java | technical-arbaab
What is Java? ☕ | Beginner's Guide to Java Programming
What is Java? ☕ | Beginner's Guide to Java Programming
an image of a man opening a atm machine with the words,'how do you use it? '
an image of a man opening a atm machine with the words,'how do you use it? '
a screen with the text 2 reverse an array description description description description description description description description description description description description description description description description description description description description description description description
a screen with the text 2 reverse an array description description description description description description description description description description description description description description description description description description description description description description description
Java if Statement 🚦 | Make Smart Decisions with Code!
Java if Statement 🚦 | Make Smart Decisions with Code!
What are Arrays in Java?
What are Arrays in Java?
Introduction to Java (Hindi) | What is Java? Explain with Syntax and Example
Introduction to Java (Hindi) | What is Java? Explain with Syntax and Example
Java Thread | Multithreading Basics
Java Thread | Multithreading Basics

To take your Java GUI programming skills to the next level, consider exploring Swing or JavaFX next. Happy coding!