Once you have defined a window listener, with an appropriate listener
method, and have connected a window-listener instance to a particular
window, your application's window-displaying frame is ready to handle mouse
clicks on the window-closing button. Whenever there is such a click,
Java activates machinery, defined by the programmers that implemented the
JFrame
class, that does the following:
WindowEvent
instance
windowClosing
method with the connected listener as the
target and the WindowEvent
instance as an ordinary argument
Then, the windowClosing
methoddefined in the instance's
classdoes its intended work, shutting down the application by calling the
exit
method.