R
Ryan Stewart
I have a class that needs to do some shutdown processing when the user
exits. However, if I use the following code, it seems to end program
execution before the shutDown() method is complete. (OuterClass is a
JFrame.)
private class WinCloser extends WindowAdapter {
public void windowClosing (WindowEvent we) {
OuterClass.this.shutDown();
System.exit(0);
}
}
One way I've found to deal with it is to do the following:
private class WinCloser extends WindowAdapter {
public void windowClosing (WindowEvent we) {
OuterClass.this.setVisible(false);
OuterClass.this.shutDown();
try{Thread.sleep(1000);}catch(Exception e){}
System.exit(0);
}
}
Like that the window goes away so it appears closed to the user, and the
program has an additional second to finish its shutdown procedures. This
seems sloppy to me, though. Is there a better way to do this?
exits. However, if I use the following code, it seems to end program
execution before the shutDown() method is complete. (OuterClass is a
JFrame.)
private class WinCloser extends WindowAdapter {
public void windowClosing (WindowEvent we) {
OuterClass.this.shutDown();
System.exit(0);
}
}
One way I've found to deal with it is to do the following:
private class WinCloser extends WindowAdapter {
public void windowClosing (WindowEvent we) {
OuterClass.this.setVisible(false);
OuterClass.this.shutDown();
try{Thread.sleep(1000);}catch(Exception e){}
System.exit(0);
}
}
Like that the window goes away so it appears closed to the user, and the
program has an additional second to finish its shutdown procedures. This
seems sloppy to me, though. Is there a better way to do this?