USE ADAPTER CLASSES TO SIMPLIFY GUI APPLICATION CODE Some interfaces declare non-needed methods in every implementation. Typical examples of this type of interface include the java.awt.event.Listener subclasses like WindowListener that define many different notification events in a single interface. If a new class implements such an interface, all the defined methods must be implemented to get by the compiler. But developers are often only interested in one or two of the available event types. In order to avoid having to provide empty implementations of all these event types, an Adapter class can be used to minimize the work required to use the given interface. Adapter classes, like java.awt.event.WindowAdapter, provide default implementations for their primary interface methods. These classes are abstract, so to use them, they need to be subclassed. The simplest way to do this is via an anonymous inner class declaration that overrides the methods of interest. Here is an example class that provides notice of two types of window events (out of the seven available) and exits the application when the window is closed: import java.util.*; import javax.swing.*; import java.awt.event.*; public class WindowAdapterTest { public static void main(String[] args) { JFrame win = new JFrame(); win.setSize(100,100); win.setLocation(100,100); win.addWindowListener(new WindowAdapter(){ public void windowOpened(WindowEvent wev) { System.out.println("Window has opened"); } public void windowClosing(WindowEvent wev) { System.out.println("Window is closing"); System.exit(0); } }); win.setVisible(true); } } However, there are drawbacks to this method. Since Adapters are classes, rather than interfaces, they must be subclassed and can't be used in conjunction with other adapters to add multiple behaviors to a single class. Also, if empty or default interface methods implementations of interface methods are not acceptable in practice for a given interface, then the interface is not a good candidate for an Adapter abstract class. When working with AWT Listener interfaces, or when designing new APIs for use by other developers, Adapter classes provide a useful shortcut to eliminate empty implementations of unneeded interface methods.