com.croftsoft.core.gui
Class ShutdownWindowAdapter

java.lang.Object
  extended by java.awt.event.WindowAdapter
      extended by com.croftsoft.core.gui.ShutdownWindowAdapter
All Implemented Interfaces:
WindowFocusListener, WindowListener, WindowStateListener, EventListener

public class ShutdownWindowAdapter
extends WindowAdapter

Performs a graceful shutdown of a program when the window is closed.

  1. Prompts for shutdown confirmation.
  2. Calls the window hide() method.
  3. Calls the destroy() method, in array order, of each of the Destroyable instances passed via the constructor argument. Any exceptions are caught, printed, and ignored.
  4. Calls the window dispose() method.
  5. Calls System.exit(0).

Example:

 jFrame.setDefaultCloseOperation (
   javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE );

 jFrame.addWindowListener (
   new ShutdownWindowAdapter ( this, "Exit Program?" ) );
 

Version:
$Date: 2006/01/13 18:47:08 $, 2001-03-06
Author:
David Wallace Croft

Constructor Summary
ShutdownWindowAdapter()
           
ShutdownWindowAdapter(Destroyable destroyable)
          Convenience constructor.
ShutdownWindowAdapter(Destroyable[] destroyables)
          Convenience constructor.
ShutdownWindowAdapter(Destroyable[] destroyables, String shutdownConfirmationPrompt)
          Convenience constructor.
ShutdownWindowAdapter(Destroyable[] destroyables, String shutdownConfirmationPrompt, String shutdownConfirmationTitle)
          Main constructor.
ShutdownWindowAdapter(Destroyable destroyable, String shutdownConfirmationPrompt)
          Convenience constructor.
 
Method Summary
 void windowClosing(WindowEvent windowEvent)
           
 
Methods inherited from class java.awt.event.WindowAdapter
windowActivated, windowClosed, windowDeactivated, windowDeiconified, windowGainedFocus, windowIconified, windowLostFocus, windowOpened, windowStateChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShutdownWindowAdapter

public ShutdownWindowAdapter(Destroyable[] destroyables,
                             String shutdownConfirmationPrompt,
                             String shutdownConfirmationTitle)
Main constructor.

Parameters:
destroyables - May be null.
shutdownConfirmationPrompt - If null, no shutdown confirmation prompt dialog will be given.
shutdownConfirmationTitle - If null, the shutdownConfirmationPrompt value will be used.

ShutdownWindowAdapter

public ShutdownWindowAdapter(Destroyable[] destroyables,
                             String shutdownConfirmationPrompt)
Convenience constructor.
 this ( destroyables, shutdownConfirmationPrompt, null );
 


ShutdownWindowAdapter

public ShutdownWindowAdapter(Destroyable destroyable,
                             String shutdownConfirmationPrompt)
Convenience constructor.
 this (
   new Destroyable [ ] { destroyable },
   shutdownConfirmationPrompt );
 


ShutdownWindowAdapter

public ShutdownWindowAdapter(Destroyable[] destroyables)
Convenience constructor.
 this ( destroyables, null );
 


ShutdownWindowAdapter

public ShutdownWindowAdapter(Destroyable destroyable)
Convenience constructor.
 this ( new Destroyable [ ] { destroyable } );
 


ShutdownWindowAdapter

public ShutdownWindowAdapter()
Method Detail

windowClosing

public void windowClosing(WindowEvent windowEvent)
Specified by:
windowClosing in interface WindowListener
Overrides:
windowClosing in class WindowAdapter

CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)