
, 8.8 Painting with Swing 129
System. exit (0) ;
The listener registration is performed by the statement
this. addWindowListener(new MyWindowAdapter() ) ;
Note we do not register the application object to act as a listener, but an instance of the
MyWindowAdapter class. The component for which we are registering a listener is the component
involved when a user shuts the main window. This component is the current frame instance,
identified by the keyword this.
If we create only a single object of the
MyWindowAdapter
class, we can dispense with giving
the adapter subclass a name by using an anonymous inner class. We can ...