The Container is a component in AWT that can contain another components like buttons, textfields, labels etc. The classes that extends Container class are known as container such as Frame, Dialog and Panel. It is basically a screen where the where the components are placed at their specific locations. Thus it contains and controls the layout of components.
There are four types of containers in Java AWT:
- Window
- Panel
- Frame
- Dialog
Window
The window is the container that does not have borders
and menu bars. A frame, dialog or another window must be used for creating a
window. An instance of Window class needs to be created to create this
container.
Following is the declaration for java.awt.Window class:
public class Window extends Container implements
Accessible
A window can act as a container of information –
outputs,drawings etc. Even applets make use of window to display the
information.
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.
Following is the declaration for java.awt.Panel class:
public class Panel extends Container implements Accessible
Any other components can be added to a panel using
add() method. They can be even resized using setSize(),setBounds() and
setPreferredSize(). Components can be positioned in a panel using
setLocation().
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. They are the child windows which users create within the
applets for stand alone applications.
Following is the declaration for java.awt.Frame class:
public class Frame extends Window implements
MenuContainer
Dialog
The Dialog control represents a top level window
with a border and a title used to take some form of input from the user. It
inherits the Window class. Unlike Frame, it doesn't have maximize and
minimize buttons.
Following is the declaration for java.awt.Dialog class:
public class Dialog extends Window
No comments:
Post a Comment