// Insert into View constructor
this.getApplication().addExitListener(new ExitHandler());
// ...
//
// Add inner class event handler for app exit to your View class
class ExitHandler implements org.jdesktop.application.Application.ExitListener
{
public boolean canExit(EventObject e) {
// In your CloseApp() method set boolean flag bCanExit to true or false
// By the way it is a perfect place for App cleanup
return bCanExit; // true or false
}
public void willExit(EventObject e)
{
}
}
this.getApplication().addExitListener(new ExitHandler());
// ...
//
// Add inner class event handler for app exit to your View class
class ExitHandler implements org.jdesktop.application.Application.ExitListener
{
public boolean canExit(EventObject e) {
// In your CloseApp() method set boolean flag bCanExit to true or false
// By the way it is a perfect place for App cleanup
return bCanExit; // true or false
}
public void willExit(EventObject e)
{
}
}
public class MyProjectApp extends SingleFrameApplication {
@Override protected void startup() {
show(new MyProjectAppView(this));
}
// ....
public static void main(String[] args) {
launch(MyProjectApp.class, args);
}
}
// ...... In MyProjectAppView constructor:
JFrame frm = getFrame();
// I set the DO_NOTHING_ON_CLOSE flag here:
frm.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frm.setResizable(false);
// I add closing listener
frm.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
CloseApp();
}
});
/ /....
@Action
public void CloseApp(){
// Returns YES = true , NO = false
if( Question("Do you really want to quit?") ){
getFrame().dispose();
System.exit(0);
}
}