Java AWT Tutorial
Java AWT Tutorial
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.
Panel
The Panel is the container that doesn't contain title bar and
menu bars. It can have other components like button, textfield
etc.
Frame
The Frame is the container that contain title bar and can have
menu bars. It can have other components like button, textfield
etc.
The setBounds(int xaxis, int yaxis, int width, int height) method is used in the above
example that sets the position of the awt button.
AWT Example by Association
Let's see a simple example of AWT where we are creating instance of Frame class. Here, we are
showing Button component on the Frame.
First2.java
ActionEvent ActionListener
MouseWheelEvent MouseWheelListener
KeyEvent KeyListener
ItemEvent ItemListener
TextEvent TextListener
AdjustmentEvent AdjustmentListener
WindowEvent WindowListener
ComponentEvent ComponentListener
ContainerEvent ContainerListener
FocusEvent FocusListener
Steps to perform Event Handling
Following steps are required to perform event handling:
Registration Methods
For registering the component with the Listener, many classes provide the registration methods.
For example:
o Button
o MenuItem
o TextField
o TextArea
o Checkbox
o Choice
o List
1. Within class
2. Other class
3. Anonymous class