This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript 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: 7719
142
  • 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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!