import java.awt.*;
import java.awt.event.*;

/**
  * a quitting class, used when windows are closed or
  * quit menu item chosen (or any other quit action event)
  * <P>
  *
  * pattern: uses singleton for one instance per program
  * <P>
  *
  * inheritance: subclasses can override doQuit() for application-specific
  * cleanup
  *
  * @author Owen Astrachan
  */

public class Quitter extends WindowAdapter implements ActionListener
{
    public static Quitter getInstance()
    {
	if (ourInstance == null)
	{
	    ourInstance = new Quitter();
	}
	return ourInstance;
    }

    private Quitter()
    {
	// private constructor, creatable only through getInstance
    }
    
    public void windowClosing(WindowEvent e)
    {
	doQuit();
    }

    public void actionPerformed(ActionEvent e)
    {
	doQuit();
    }

    /**
      * the function called for any quit event, e.g., window closing
      * or quit menu item for chosen
      */
    
    protected void doQuit()
    {
	System.exit(0);
    }

    private static Quitter ourInstance = null;
}
