Adapter classes provide default implementations of listener interface methods to avoid implementing unused methods. The WindowAdapter class is an adapter for the WindowListener interface. It implements empty method bodies for the WindowListener's seven abstract methods. This allows classes to extend WindowAdapter and only override the needed methods rather than all methods of the WindowListener interface. Adapters exist for convenience by providing listener object implementations with default empty method bodies.
2. 2
Adapter class
It is one which contains null body definition for those methods which
are inheriting from appropriate Listener.
In java.awt.event.* we have Listener interface called WidowListener
which contains seven abstract methods. In the derived class implements
WindowListener interface; it is mandatory for derived class to define all
the methods even though the derived class is not required.
If the derived class wants to define the required methods, it has to
extend its corresponding adapter class called
java.awt.event.WindowAdapter and this class contains null body
definition for WindowListener interface methods.
Therefore which our Listener interface contains more than one
undefined method for that
Listener interfaces we have the appropriate adapter class whose general
notation is XXXAdapter.
4. Adapters are abstract classes for receiving various events. The
methods in these classes are empty. These classes exists as
convenience for creating listener objects.
4
5. import java.awt.*; import java.awt.event.*;
class frm12 extends Frame implements WindowListener
{ frm12()
{ super("window Listener");
addWindowListener(this);
setSize(300,300);
setVisible(true); }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowOpened(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowClosing(WindowEvent e){System.exit(0);}
}
public static void main(String []a)
{ frm12 k=new frm12(); }
}
5