public class ExitExample1 extends Application
This class adds an Application.ExitListener
that asks the
user to confirm exiting the application. The ExitListener is
defined like this:
class MaybeExit implements Application.ExitListener { public boolean canExit(EventObject e) { Object source = (e != null) ? e.getSource() : null; Component owner = (source instanceof Component) ? (Component)source : null; int option = JOptionPane.showConfirmDialog(owner, "Really Exit?"); return option == JOptionPane.YES_OPTION; } public void willExit(EventObject e) { } }When the user attempts to close the window,
Application.exit
is called by JFrame's WindowListener. The exit
method checks the ExitListener.canExit
methods
and aborts the attempt to exit if any of them return false.Application.ExitListener
Constructor and Description |
---|
ExitExample1() |
Modifier and Type | Method and Description |
---|---|
static void |
main(java.lang.String[] args) |
protected void |
shutdown()
Called when the application
exits . |
protected void |
startup()
Responsible for starting the application; for creating and showing
the initial GUI.
|
addExitListener, end, exit, exit, getContext, getExitListeners, getInstance, getInstance, hide, initialize, launch, quit, ready, removeExitListener, show
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
protected void startup()
Application
This method is called by the static launch
method,
subclasses must override it. It runs on the event dispatching
thread.
startup
in class Application
Application.launch(java.lang.Class<T>, java.lang.String[])
,
Application.initialize(java.lang.String[])
,
Application.shutdown()
protected void shutdown()
Application
exits
.
Subclasses may override this method to do any cleanup
tasks that are neccessary before exiting. Obviously, you'll want to try
and do as little as possible at this point. This method runs
on the event dispatching thread.public static void main(java.lang.String[] args)