The key to understanding how Java deals with events is to understand listener classes. You define listener classes by extending other listener classes or by implementing listener interfaces. Either way, you are sure to include certain prescribed method definitions in those classes.
Suppose, for example, that you define a listener class that extends the
WindowListener
interface. That interface requires you to define a
windowClosing
method, among others. You can define your
windowClosing
method, as shown later, in Segment 685,
to shut down your application.
Once you have defined a listener class, you can connect instances of your
listener class to your application's window-displaying frame. Then,
Java calls your
windowClosing
method whenever a user of your
application's window-displaying frame clicks the window's close button.