Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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

when to use ActionListener interface

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when to use ActionListener interface in a program , i am confused after watching to many interfaces , please help
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use ActionListener when
1) You got components which are capable of triggering action events
2) You are interested in receiving such events

e.g. JButton is capable of triggering action event (since it has the addActionListener() method) If you want to get notified when a particular button is pressed you would use an action listener
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks maneesh

can we also use MouseListener (in case of JButton and mouse event on it ) in place of ActionListener
if yes then what will be pros and cons of it
if no then please tell me ....why ?
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a MouseListener if you're interested in responding to mouse events. Usually you don't want that on a JButton, because "pressing" a button is more complicated than just clicking on it. For instance, you can activate it using the keyboard.
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Matthew
 
Marshal
Posts: 69782
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at this section in the Java™ Tutorials.

This looks like a Swing/AWT related question, so I shall move this discussion to our GUIs forum.
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great ....... thanks a lot Campbell Ritchie
 
    Bookmark Topic Watch Topic
  • New Topic