> Hello,
> I want to confirm the closing of frame with a Yes/No Dialog.
[quoted text clipped - 18 lines]
> }
> });
You need to alter the default 'window close' behaviour. This is done via:
...
yourFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
...
yourFrame.addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
...
// Dialog, whatever ...
...
if (choice == 0) System.exit(0);
// No need to do anything else here ...
}
}
);
See:
http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html#window
events
for more details.
I hope this helps.
Anthony Borla
John - 20 Mar 2005 01:29 GMT
Also, don't do it like this, ie don't close the application from the
dialog. Create a method
that displays the dialog and returns an identifier for the button that
was pressed, for example
you can return 0 if the Cancel button or the close button has been
pressed and 1 for the Ok
button, then, depending on the returned value, you can close the
application
from the method that calls the display method for the dialog. You'll
have to display a modal
dialog to do this, otherwise you won't have the value returned
synchronously.
>>Hello,
>>I want to confirm the closing of frame with a Yes/No Dialog.
[quoted text clipped - 49 lines]
>
> Anthony Borla