Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

add window listener on button

 
sandhiya sindhi
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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():
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic