|
-
Oct 21st, 2001, 07:26 PM
#1
Overriding close operation
I have a class that extends JFrame, and I am adding a WindowListener in the constructor like this:
Code:
//...
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
if (exit()) System.exit(0);
}
});
//...
where exit() throws up a confirmDialog and returns whether or not the user clicks the Yes button. The problem is, when the user clicks the No button, the window disappears, and the app is stil running in the background. So how do I keep the window up and visible?
Thanks
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 22nd, 2001, 02:11 AM
#2
Well ...
A simple option is to make sure the window is visible by using an else clause, something like this:
Code:
//...
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
if (exit()) System.exit(0);
else this.setVisible(true);
}
});
//...
.
-
Oct 26th, 2001, 03:13 PM
#3
Sorry, it still disappears for some reason.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 27th, 2001, 04:18 AM
#4
Well ...
What on earth is the exit() function? If it's a custom function you have made, which is what I suspect, try changing its name to something like ConfirmExit. I think the name exit() might be playing mischief.
.
-
Nov 2nd, 2001, 03:36 PM
#5
Check out
public void setDefaultCloseOperation(int operation)
for JFrame.
I think you want something like:
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
perhaps right before
this.addWindowListener(new WindowAdapter()...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|