Event Handling In Java Part II - Open The Window And Inhale Java In The Air (
Page 3 of 6 )
Handling Windows Events: When you use interfaces for creating listeners,
the listener class has to override all the methods that are declared in the
interface. Some of the interfaces have only one method, whereas
others(windowListener) have many. So even if you want to handle only a single
event, you have to override all the methods. To overcome this, the event
packages provide seven adapter classes, which we will see shortly. Now coming
back to handle window-related events, you need to register the listener object
that implements the windowListener interface. The WindowListener interface
contains a set of methods that are used to handle window events.
| Category
|
Event
|
Method |
| Windows
Events |
The user clicks
on the cross button. |
void windowClosing
(WindowEvent e) |
| The window opened for the first time. |
void
windowOpened (WindowEvent e) |
| The window is activated. |
void
windowActivated (WindowEvent e) |
| The window is deactivated. |
void
windowDeactivated (WindowEvent e) |
| The window is closed. |
void
windowClosed (WindowEvent e) |
| The window is minimized |
void
windowIconified (WindowEvent e) |
| The window maximized |
void
windowDeiconified (WindowEvent e) |
In the next
section we will write a sample applet so that it includes the code for window
event handling.