dcsimg
windowClosing and confirmation
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   HELIGON_Sandra
Posted On:   Thursday, February 12, 2004 06:07 AM

When the user decide to exit the application, I would like to ask him confirmation but when he choice No the frame is hide anyway. I do the following: public class XFrame extends JFrame { public XFrame() { addWindowListener(new MyWindowListener(this)); } } private class MyWindowListener extends WindowAdapter { private XFrame m_frame; public MyWindowListener(XFrame _frame) { m_frame = _frame; } public void windowClosing(WindowEvent e) { int reply = JOptionPane.showConfirmDialog("Do you really want to exit?",Exit, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);    More>>

When the user decide to exit the application,
I would like to ask him confirmation but when he
choice No the frame is hide anyway.

I do the following:

public class XFrame extends JFrame
{
public XFrame()
{
addWindowListener(new MyWindowListener(this));
}
}

private class MyWindowListener extends WindowAdapter
{
private XFrame m_frame;

public MyWindowListener(XFrame _frame)
{
m_frame = _frame;
}
public void windowClosing(WindowEvent e)
{
int reply = JOptionPane.showConfirmDialog("Do you really want to exit?",Exit, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

if (reply == JOptionPane.YES_OPTION)
{
this.setVisible(false); // hide the Frame
this.dispose();
System.exit(0); // close the application
}
}
}

I don't know what is the problem ?

   <<Less

Re: windowClosing and confirmation

Posted By:   Anonymous  
Posted On:   Sunday, February 15, 2004 12:42 AM

Hi,


add this method call to XFrame constructor:


setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);



I found that from here


--Jouni

About | Sitemap | Contact