Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

add window listener on button

 
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
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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():
 
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
 
    Bookmark Topic Watch Topic
  • New Topic