Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ClosingWindow, Jframe Question

Status
Not open for further replies.

ronnyjljr

IS-IT--Management
Nov 23, 2003
249
US
Okay here goes,

When the user closes the JFrame I want them to be prompted to confirm that they do want to close it.
I am listening for the WindowClosing event but I don't think that is correctly. If the window closing event is called, does that mean it is too late to stop it from closing?

More precisely, this code is executed but I have no clue how to stop the window from closing. Do I have to listen for a seperate event or is there something I can add here?

This is my code for the listener...

Code:
[blue]
public void windowClosing(WindowEvent arg0)
{		
	if (JOptionPane.showConfirmDialog(null,"Are you sure you want to exit?","Exit?",JOptionPane.YES_NO_OPTION)==1)
	{			
		ShutdownSockets();
	} //END IF
} //End Window Closing


[/blue]


Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
you'll have to do this first in your JFrame

setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)

and then in the windowclosing method add setvisible(false) if you want to close it and do nothing or setvisible(true) when you want to close it.



Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Hi Chrissie1,

Thanks for the reply, I also had to add a System.exit(0) call to make sure the application shuts down. Your suggestions worked perfectly.

Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top