kirk.gui.closer
Class FinishingCloser
java.lang.Object
java.awt.event.WindowAdapter
kirk.gui.closer.WindowCloser
kirk.gui.closer.FinishingCloser
- All Implemented Interfaces:
- EventListener, WindowFocusListener, WindowListener, WindowStateListener
- public class FinishingCloser
- extends WindowCloser
This class closes Window
s that generate WindowEvents
asking for it. Also, it calls finish()
of the class specified on
construction (which must implement Finisher
). This does not have to
be the same class as the Window
that is being closed.
finish()
can then do stuff before the window is being closed, and it
can even stop the window from being closed by returning false
.
Note that this elaborate implementation does not do much more than saving you
of writing some Window
closing code, but it adds to encapsulation and
you don't have to extend WindowAdapter
if you want only closing
stuff. Thus you are able to extend another class. This saves a lot of unneccesary
code of implementing WindowListener
. Also, it stays in line with just
adding a dedicated WindowCloser
. This was all I could do to make me
feel I didn't write useless code (^^)
- Version:
- 1
- Author:
- Berend Wouda
- See Also:
Window
,
Finisher
Field Summary |
private Finisher |
finisher
The object we will call the finish() method of before closing the passed
Window . |
Constructor Summary |
FinishingCloser(boolean exit,
Finisher finisher)
Constructs a FinishingCloser with the passed
Finisher and the given closing option. |
FinishingCloser(Finisher finisher)
Constructs a FinishingCloser with the passed
Finisher that does not end the program after closing. |
Method Summary |
void |
windowClosing(WindowEvent event)
Makes the associated Finisher do its thing and closes the passed
Window . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
finisher
private Finisher finisher
- The object we will call the finish() method of before closing the passed
Window
.
FinishingCloser
public FinishingCloser(boolean exit,
Finisher finisher)
- Constructs a
FinishingCloser
with the passed
Finisher
and the given closing option.
- Parameters:
exit
- true
if the program should exit after closing a
window, false
otherwise.finisher
- The associated Finisher
.
FinishingCloser
public FinishingCloser(Finisher finisher)
- Constructs a
FinishingCloser
with the passed
Finisher
that does not end the program after closing.
- Parameters:
finisher
- The associated Finisher
.
windowClosing
public void windowClosing(WindowEvent event)
- Makes the associated
Finisher
do its thing and closes the passed
Window
.
- Specified by:
windowClosing
in interface WindowListener
- Overrides:
windowClosing
in class WindowCloser
- Parameters:
event
- The event that indicates which Window
to close.