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, but it must override the appropriate method for each type of event.

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

QUESTION 6:

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