Forums Register Login

add window listener on button

+Pie Number of slices to send: Send
Hi All,
how can i add windowadapter on button
i tried like as :
Button.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}});
but it generate an error..
how can i exit from programe by clicking on EXIT button.
thanx in advance
+Pie Number of slices to send: Send
Hi,
WindowListeners listen for events sent by Windows (hence the name.)
ActionListeners listen for events sent by buttons, etc. To exit in response to a button press, use an ActionListener that calls System.exit():
+Pie Number of slices to send: Send
WindowListeners listen for events sent by Windows (hence the name.)
Just for completeness, what Ernest is saying is that you should replace the reference to the button with the reference to the JFrame or JDialog, which are descendends of java.awt.Window.
+Pie Number of slices to send: Send
Mr Ernest Friedman-Hill
THANK U VERY MUCHH FOR SUCH HELP . IT IS WORKING
THANKS TO Eugene Kononov TOO.
and I hope in future u will help me too
Thank you very much
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1468 times.
Similar Threads
how to control components of another window
How to add validation
Closing an Applet
Help please
Closing FileDialog
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:19:23.