File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes add window listener on button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "add window listener on button" Watch "add window listener on button" New topic
Author

add window listener on button

sandhiya sindhi
Ranch Hand

Joined: Sep 25, 2003
Posts: 50
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
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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():


[Jess in Action][AskingGoodQuestions]
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
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.
sandhiya sindhi
Ranch Hand

Joined: Sep 25, 2003
Posts: 50
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: add window listener on button