How to set action for close button?

user594860 picture user594860 · Feb 6, 2011 · Viewed 31.8k times · Source

I've created a stand-alone java desktop application in Netbeans 6.9. I want to set the action for the close button of my application. I want to know how and where to set the code for the action of that close button. Can anyone please help me regarding this?

Answer

RoflcoptrException picture RoflcoptrException · Feb 6, 2011

You have to register an ActionListener on your close button. In this listener you can define what do to.

How add ActionListener to JButton in Java Swing