Java Reference
In-Depth Information
void windowIconified(WindowEvent e);
//This method executes when a window is iconified.
void windowOpened(WindowEvent e);
//This method executes when a window is opened.
}
As you can see, the interface WindowListener contains several abstract methods.
Therefore, to instantiate an object of the class that implements the interface
WindowListener , that class must provide the definition of each method of the
interface WindowListener , even if a method is not used. Of course, if a method is
not used, you could provide an empty body for that method. Recall that if a class contains
an abstract method, you cannot instantiate an object of that class.
In Chapter 6, we used the mechanism of the inner class to handle events. That is, the class that
implemented the interface was defined within the class containing the application program.
Chapter 10 noted that rather than create an inner class to implement the interface, the class
containing the application program can itself implement the interface. Now a program can
generate various types of events, such as action events and window events. Java allows a class
to implement more than one interface. However, Java does not allow a class to extend the
definition of more than one class; that is, Java does not support multiple inheritance.
For interfaces such as WindowListener that contain more than one method, Java
provides the class WindowAdapter . The class WindowAdapter implements the
interface WindowListener by providing an empty body for each method of the
interface WindowListener . The definition of the class WindowAdapter is:
public class WindowAdapter implements WindowListener
{
void windowActivated(WindowEvent e)
{
}
void windowClosed(WindowEvent e)
{
void windowClosing(WindowEvent e)
{
}
void windowDeactivated(WindowEvent e)
{
}
void windowIconified(WindowEvent e)
{
}
void windowOpened(WindowEvent e)
{
}
}
Search WWH ::




Custom Search