In this article AWT in Java we give the information about it is a platform dependent API that creates a graphical user interface (GUI) for Java programs.

AWT in Java:

The full name of AWT is abstract window toolkit.

It is a platform dependent API that creates a graphical user interface (GUI) for Java programs.

In other words, “java awt is an API through which GUI or Windows based applications are developed in Java.”

It has a large number of classes and methods with which we can create GUI applications. Like:- textbox, checkbox, button etc.

To create Java components we have to use java.awt package.

The java awt components are platform dependent, that is, the components appear differently according to the operating system. That is, their look and feel will be according to the operating system. Suppose we have created a textbox, that textbox will look different in Windows, different in Mac OS and different in UNIX.

It is a heavyweight, that is, its components use the resources of the operating system.

Nowadays AWT is rarely used because it is platform dependent and heavyweight. Java swing is used instead. Because through this we can implement GUI well and it is light weight.

Java AWT hierarchy:-

Java AWT classes are shown below:-

AWT in Java

Components:- All elements like buttons, text fields, scrollbars etc. are components.

Container:- Container is a component of AWT which contains other components such as buttons, textfield, checkbox, label etc. and it also controls the layout of the components.

Container is a subclass of component class.

Window:- Window is a container which has no border and menu bar. To create a window we have to use frame and dialog or other windows.

Panel:- Panel does not contain title bar, menu bar or border. It is used to contain components. Like:- button, textfield etc.

Frame:- Frame is a container that contains the title bar, menu bar or border. It also contains other components like:- buttons, textfields, scrollbars etc. This container is most used in developing applications in java AWT.

Java AWT methods:-

method description
public void add(Component c) It is used to add a component to the component.
public void setSize(int width,int height) It is used to set the size of the component.
public void setLayout(LayoutManager m) It is used to define the layout manager for the component.
public void setVisible(boolean status) It is used to set the visibility of the component.

AWT Program in Java:

// importing Java AWT class
import java.awt.*;

// extending Frame class to our class AWTExample1
public class AWTExample1 extends Frame

{

// initializing using constructor
AWTExample1()

{

// creating a button
Button b = new Button(“Click Me!!”);

// setting button position on screen
b.setBounds(30,100,80,30);

// adding button into frame
add(b);

// frame size 300 width and 300 height
setSize(300,300);

// setting the title of Frame
setTitle(“This is our basic AWT example”);

// no layout manager
setLayout(null);

// now frame will be visible, by default it is not visible
setVisible(true);
}

// main method
public static void main(String args[])

{
// creating instance of Frame class
AWTExample1 f = new AWTExample1();
}
}

Some More: 

POP- Introduction to Programming Using ‘C’

DS – Data structure Using C

OOP – Object Oriented Programming 

Java Programming

DBMS – Database Management System

RDBMS – Relational Database Management System

Join Now: Data Warehousing and Data Mining 

Leave a Reply

Your email address will not be published. Required fields are marked *