JInternalFrame listener...help!

Ok, i am making a paint program where the pictures are stored in JInternalFrames.

when the user closes a frame i have a InternalFrame listener as follows:

publicvoid internalFrameClosing(InternalFrameEvent e){

JInternalFrame fr = desktop.getSelectedFrame();

if(fr.getLayer() == JDesktopPane.DEFAULT_LAYER)

{

int response = JOptionPane.showConfirmDialog(null,"This will delete any unsaved changes, would you like to save?",

"Confirm Save",

JOptionPane.YES_NO_CANCEL_OPTION,

JOptionPane.WARNING_MESSAGE );

if (response == JOptionPane.CANCEL_OPTION)

{

//System.out.println("woof");

return;

}

if (response == JOptionPane.YES_OPTION)

{

doSave();

}

}

close();

}

for some reason when i press cancel it doesnt cancel the closing of the frame, i thought return would work but clearly not.

Is there any other way to stop the frame closing once the X has been clicked?

thanks

[1546 byte] By [boblettoj99a] at [2007-11-27 6:30:10]
# 1
when creating the frames, call setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);that way it won't close without you disposing it.Also, unless you need the layer check for something else, you don't need that.
bsampieria at 2007-7-12 17:54:36 > top of Java-index,Desktop,Core GUI APIs...
# 2
will that listener still be called though when i click the x?
boblettoj99a at 2007-7-12 17:54:36 > top of Java-index,Desktop,Core GUI APIs...
# 3
Yes. The default "default close operation" is DISPOSE_ON_CLOSE, which means it fires the event then disposes. DO_NOTHING... will still fire the event, then you have to decide if it should really close.
bsampieria at 2007-7-12 17:54:36 > top of Java-index,Desktop,Core GUI APIs...
# 4
aaah yes that works perfectly thanks alot, sending dukes
boblettoj99a at 2007-7-12 17:54:36 > top of Java-index,Desktop,Core GUI APIs...