AWT Program in Java
AWT stands for Abstract window toolkit is an Application programming interface (API) for creating Graphical User Interface (GUI) in Java. It allows Java programmers to develop window-based applications.
AWT provides various components like button, label, checkbox, etc. used as objects inside a Java Program. AWT components use the resources of the operating system, i.e., they are platform-dependent, which means, component's view can be changed according to the view of the operating system. The classes for AWT are provided by the Java.awt package for various AWT components.
The following image represents the hierarchy for Java AWT.
The component class stands at the top of the AWT hierarchy, is an abstract class that contains all the properties of the component visible on the screen. The Component object contains information about the currently selected foreground and background color. It also has information about the currently selected text color.
The container is a component that contains other components like button, textfield, label, etc. However, it is a subclass of the Component class.
The panel can be defined as a container that can be used to hold other components. However, it doesn't contain the title bar, menu bar, or border.
A window can be defined as a container that doesn't contain any border or menu bar. It creates a top-level view. However, we must have a frame, dialog, or another window for creating a window.
The frame is a subclass of Window. It can be defined as a container with components like button, textfield, label, etc. In other words, AWT applications are mostly created using frame container.
Java AWT Example
Consider the following simple example of Java AWT in which we have shown an awt component button by setting its placement and window frame size.
Java awt Example (extending Frame Class)
Consider the following program in which we have created a user's form GUI, which has three fields, i.e., first name, last name, and date of birth.