Java AWT
Java AWT
Java AWT
The java.awt package provides classes for AWT API such as TextField, Label,
TextArea, RadioButton, CheckBox, Choice, List etc.
Window
The window is the container that have no borders and menu bars. You must use
frame, dialog or another window for creating a window. We need to create an
instance of Window class to create this container.
Panel
The Panel is the container that doesn't contain title bar, border or menu bar. It is
generic container for holding the components. It can have other components
like button, text field etc. An instance of Panel class creates a container, in
which we can add components.
Frame
The Frame is the container that contain title bar and border and can have
menu bars. It can have other components like button, text field, scrollbar etc.
Frame is most widely used container while developing an AWT application.
Useful Methods of Component Class
Method Description
public void add(Component c) Inserts a component on this component.
public void setSize(int width,int height) Sets the size (width and height) of the component.
public void setLayout(LayoutManager
Defines the layout manager for the component.
m)
Changes the visibility of the component, by default
public void setVisible(boolean status)
false.
Try this…!
1. In the following example, we are implementing the windowClosing().
2. Let's see a simple example of AWT where we are inheriting Frame class. Here, we are showing
Button component on the Frame.