I created a standalone Java application in NetBeans 6.9. I want to set an action for the close button of my application. I want to know how and where to set the code for the action of this close button. Can anyone help me in this regard?
You need to register the ActionListener on the close button. In this listener, you can determine what to do.
How to add ActionListener to JButton in Java Swing
Right click on the button, then > Events > Action > actionPerformed. NetBeanswill generate an action listener for you :)
> Events > Action > actionPerformed
NetBeans
: , .
, java swing
, " , setDefaultButton() , ". . JButton.
setDefaultButton()
, ( , Windows, !!!)
, , , , ( ) , , , , , , , /, , /.
, ( , ), ,
, ,
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Oracle