JAVA AWT Introduction

Java AWT (Abstract Windowing Toolkit) is an API which contains large number of classes and methods used to create and manage windows GUI application.

AWT is the basic fundamentals upon which Swing have developed. It is used for GUI programming in Java. But now a days it is merely used because most GUI java programs are implemented using Swing because of its rich implementation of GUI controls and light-weighted nature.

Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. AWT is heavyweight i.e. its components uses the resources of system because they are being generated by underlying operating system (OS). For example if you are instantiating a text box in AWT that means you are actually asking OS to create a text box for you.

JAVA AWT Hierarchy

The Java AWT hierarchy classes are given below.

awt hirerchy

Component Class

Component class is at the top of AWT hierarchy.

Component is an abstract class that encapsulates all attribute of visual component.

A component object is responsible for remembering the current foreground and background colours and the currently selected text font. All the elements like buttons, text fields, scrollbars etc are known as components.


The Container is a component in AWT that can contain another components like buttons, textfields, labels etc. Container is a subclass of component class.


The Panel is the container that doesn't contain title bar and menu bars. It can have other components like button, textfield etc.

Window Class

Window class creates a top level window. Window does not have borders and menu bar.


The Frame is a sub class of Window .The Frame is the container that contain title bar and can have menu bars. It can have other components like button, textfield etc.

Java AWT Example

To develop a GUI, we need a frame. There are two ways to create a frame in AWT.

  • By extending Frame class
  • By creating the object of Frame class

AWT Example 1: creating Frame by extending Frame class

import java.awt.*;
public class FirstExample extends Frame
Button b=new Button("OK");
// setting button position on screen

//adding button into frame

//Setting Frame width and height

//Setting the title of Frame
setTitle("My First AWT example");

//Setting the layout for the Frame
setLayout(new FlowLayout());

/* By default frame is not visible so
* we are setting the visibility to true
* to make it visible.
public static void main(String args[])
// Creating the instance of Frame
FirstExample f=new FirstExample();



AWT Example 2: creating Frame by creating instance of Frame class

import java.awt.*;
public class SecondExample
//Creating Frame
Frame f=new Frame();

//Creating a label
Label lb = new Label("UserName: ");

//adding label to the frame

//Creating Text Field
TextField t = new TextField();

//adding text field to the frame

//setting frame size
f.setSize(500, 300);

//Setting the layout for the Frame
f.setLayout(new FlowLayout());

public static void main(String args[])
SecondExample se = new SecondExample();




Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Projects

SILAN Technology
Call to: 9439202111  |  9658317757  |  0674-2361252