AWT Hierarchy
AWT Hierarchy
• Java AWT (Abstract Window Toolkit) is an API to develop GUI or window-based applications in
java.
• 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 are using the resources of OS.
• The java.awt package provides classes for AWT api such as TextField, Label, TextArea,
RadioButton, CheckBox, Choice, List etc.
• AWT is rarely used now days because of its platform dependent and heavy-weight nature. Swing is
a preferred API for window based applications because of its platform independent and light-weight
nature.
AWT hierarchy
Types of containers:
As explained above, a container is a place wherein we add components like text field, button, checkbox etc.
There are four types of containers available in AWT: Window, Frame, Dialog and Panel. As shown in the
hierarchy diagram above, Frame and Dialog are subclasses of Window class.
Method Description
public void setSize(int width,int height) Sets the size (width and height) of the component.
public void setLayout(LayoutManager m) Defines the layout manager for the component.
public void setVisible(boolean status) Changes the visibility of the component, by default false.
AWT Classes
The AWT classes are contained in the java.awt package. It is one of Java’s largest packages.
Fortunately, because it is logically organized in a top-down, hierarchical fashion, it is easier
to understand and use .
Class Description
//Creating a label
Label lb = new Label("UserId: ");
fr.setVisible(true);
}
public static void main(String args[])
{
Example2 ex = new Example2();
}
}
Output: