A good answer might be:

  1. In the JFrame class.

Extending WindowAdapter

addWindowListener() is used in a JFrame to register of the listener object for this frame. Here is a class definition that extends WindowAdapter.

public class WindowQuitter extends WindowAdapter
{
  public void windowClosing( WindowEvent e )
  {
    System.exit( 0 );  // what to do for this event
  }
}

The WindowAdapter class has many methods in it. To respond to window closing events, override the windowClosing() method. The Java system sends this method a WindowEvent object when the close window button is clicked.

A listener can respond to several types of events. Override the appropriate method for each type of event. For now let us look only at windowClosing events.

Your program can do whatever it needs to in response to the event. In WindowQuitter, we exit the program.

QUESTION 6:

Would a large application exit the entire program when a "close window" button is clicked?