Java Abstract Window Toolkit

Java AWT is known as Abstract window Toolkit is an API used in to develop windows based applications.

Awt components are platform dependent because they are displayed according to the view or screen of the operating system.

AWT is heavyweight because its components are using resources of operating system.

Java.awt package provides some classes:

1. TextField

2. Button

3. Label

4. Chekbox



Container is the component of awt that contains other components like button, textfield, label.

Types of Containers :

Window – Window is container but it does not have borders and menu. If you want to create window, you can use frame and dialog.

Frame - The Frame is the container that can contain the title bar and menu bar. It can have other components like button, text field, etc.

Panel - The Panel is the container that doesn’t contain the title bar and menu bar. It can have other components like button, text field, etc.

Dialog - Dialog is the container having border and title. We cannot create an instance of the Dialog class without an associated instance of the respective Frame class.

Program to create a button by extends Frame class

import java.awt.*;
import java.awt.Event.*;
public class AwtExample extends Frame
        Button b=new Button("Click"); 
        setTitle("Program by extends Frame"); 
        setLayout(new FlowLayout());
    public static void main(String[] args){  
         AwtExample ae=new AwtExample();  

Output :


Program to create TextField by creating instance of Frame class.

In this program, we are copy the already existing file into another file, it it does not exist it will shoe an exception otherwise it will create successfully.

import java.awt.*;
public class AwtExample2 {
      Frame fr=new Frame();       
      Label lb = new Label("User Name"); 
      TextField t = new TextField();
      fr.setSize(300, 150);  
      fr.setLayout(new FlowLayout());
   public static void main(String args[])
       AwtExample2 ae = new AwtExample2();