Results 1 to 5 of 5
- 05-06-2011, 09:03 AM #1
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
JFrame always closes despite of option chosen
I'm trying to write a window handler but for some reason, my JFrame always closes when user clicks the 'X' button, even if the user clicks 'No' or 'Cancel' in the confirmation box. Can anyone check the code for me please?
private class WindowHandler implements WindowListener
{
public void windowClosing(WindowEvent arg0)
{
if (JOptionPane.showConfirmDialog(null, "Are You Sure?", "Quitting",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)
System.exit(0);
}
public void windowOpened(WindowEvent arg0) {
}
public void windowClosed(WindowEvent arg0) {
}
public void windowIconified(WindowEvent arg0) {
}
public void windowDeiconified(WindowEvent arg0) {
}
public void windowActivated(WindowEvent arg0) {
}
public void windowDeactivated(WindowEvent arg0) {
}
}
- 05-06-2011, 09:16 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Add the following line when you initialize your window:
kind regards,Java Code:setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-06-2011, 09:47 AM #3
Extend WindowAdapter instead of implementing WindowListener and you won't need to have a bunch of empty methods.
db
- 05-06-2011, 04:24 PM #4
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
Thanks Jos! it worked like a charm! :D
- 05-06-2011, 04:28 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
JWindow closes after a particular key combination
By chyrl in forum AWT / SwingReplies: 9Last Post: 05-05-2010, 04:33 PM -
how do i count the letter that the user had chosen?
By ashin in forum Advanced JavaReplies: 4Last Post: 10-08-2009, 05:00 PM -
Javascript: Main page closes when there is any action performed on the pop-up window
By MAGNUM in forum New To JavaReplies: 2Last Post: 03-23-2009, 09:02 AM -
[SOLVED] Application should wait until a Dialog closes
By hannehomuth in forum Advanced JavaReplies: 2Last Post: 07-24-2008, 02:51 PM -
Middle Click Closes Tab Eclipse Plugin 1.0.0
By JavaBean in forum Java SoftwareReplies: 0Last Post: 10-20-2007, 05:59 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks