Sharkysoft home

lava.gui
Class FrameCloser

java.lang.Object
  |
  +--java.awt.event.WindowAdapter
        |
        +--lava.gui.FrameCloser
All Implemented Interfaces:
java.util.EventListener, java.awt.event.WindowListener

public class FrameCloser
extends java.awt.event.WindowAdapter

Automatically closes frame.

Details: FrameCloser simplifies the task of creating closable Frames. (By default, Frames do not close automatically when the close command is selected.) To make a Frame closable, simply create a new FrameCloser with the Frame as a parameter. There is no need to retain the constructed instance. An additional parameter can be supplied to indicate whether the whole program should exit when the frame is closed.

Example:

Frame frame = new Frame ("frame title here");
// true means to exit the program when the frame is closed:
new FrameCloser (frame, true);
// now configure and populate frame...

Notice that the newly constructed FrameCloser is not retained in any variable, because there is no need to refer to the FrameCloser again.

Note: Note that some Java graphics libraries offer a subclass of Frame that closes automatically, such as "ClosableFrame." While this type of solution is also effective, the FrameCloser approach is more versatile because it allows you to arbitrarily add a closable property to already existing Frame subclasses.

Author:
Sharky

Constructor Summary
FrameCloser(java.awt.Frame frame)
          Initializes with default values.
FrameCloser(java.awt.Frame frame, boolean exit)
          Sets exit feature.
 
Method Summary
 void windowClosing(java.awt.event.WindowEvent e)
          Reserved method.
 
Methods inherited from class java.awt.event.WindowAdapter
windowActivated, windowClosed, windowDeactivated, windowDeiconified, windowIconified, windowOpened
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FrameCloser

public FrameCloser(java.awt.Frame frame,
                   boolean exit)
Sets exit feature.

Details: This constructor initializes a new FrameCloser to respond to the given Frame's close commands. The exit parameter indicates whether the program should exit when the window is closed.

Parameters:
frame - the frame to close
exit - whether the program should exit when the frame is closed (default value: false)

FrameCloser

public FrameCloser(java.awt.Frame frame)
Initializes with default values.

Details: This constructor initializes a new FrameCloser to respond to the given Frame's close commands. The window will close, but the application will not exit.

Parameters:
frame - the frame to close
Method Detail

windowClosing

public void windowClosing(java.awt.event.WindowEvent e)
Reserved method.

Details: This method responds to the Frame's windowClosing WindowEvent and is called by the AWT subsystem. Clients should not call this method.

Overrides:
windowClosing in class java.awt.event.WindowAdapter

Sharkysoft home