I need to change a boolean when the exit event is called.. any way to do that?
Printable View
I need to change a boolean when the exit event is called.. any way to do that?
I'm not 100% sure, but I think you would implement a Container Listener for this type of situation.
If this is AWT/Swing, WindowListener#windowClosing / windowClosed.
Please be more specific with your questions, and post in the appropriate section of the forums. There are separate sections for AWT/Swing and SWT/JFace.
It does rather look like what you really need (again, if this is Swing) is a modal JDialog.
db
Code:Boolean b = new Boolean(true);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
//Set up a listener that calls the method closeMyFrame() when X is pressed
public void closeMyFrame(){
b = false;
System.exit(0);
}
1. Where did the question state your assumption, that the program should terminate when the frame is closed?
2. Even if that is assumed, what do you gain by setting the value of a variable that is about to be lost on VM exit?
3. Even if that made sense, what would be wrong with the JFrame's initial default close operation of HIDE_ON_CLOSE? Why DO_NOTHING_ON_CLOSE?
4. and most important: Don't try to spoonfeed. In the best case, it passively deprives the questioner of a learning opportunity. In the worst case (and this is one of those) it's totally misleading and actively detracts from the learning experience.
db