With the skills that you have developed so far from Part I of the tutorial, you can design a graphical user interface with beauty and easy. Let us refresh ourselves before we proceed, Events are method calls that Javas windowing system performs whenever any element of a user interface is manipulated.
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.
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.