Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Closing JFrame  RSS feed

 
Lazaro Caruso
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have class which extends JFrame and implements ActionListener. Is there an Action or something similar, that I could "catch" before closing window?
You know - someone is clicking cross in top right corner of window, and I would like f.e. to print some "bye message".
 
Stephan van Hulst
Saloon Keeper
Posts: 6980
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE), and then add a WindowListener (tip: WindowAdapter) to handle windowClosing.

After you print your message, you can proceed to close the window by invoking dispose() on your frame, or you can exit the program outright.
 
Lazaro Caruso
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, it's working
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!