• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

setAction and addActionListener

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

If I have a button on the frame and I have added an actionListener and I have set the action using setAction as well. Which will be called first actionPerformed in ActionListener class for in Action class? Please let me know.

Thanks & Regards
Ashwin
 
Bartender
Posts: 11445
18
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ash Kondhalkar:

If I have a button on the frame and I have added an actionListener and I have set the action using setAction as well. Which will be called first actionPerformed in ActionListener class for in Action class? Please let me know.



Java doesnt give any kind of guarantee about the sequence in which the registered listeners are notified in case of event generation.

Simplest thing for you would be to out println statements in both and see which is printed first.
 
Marshal
Posts: 64705
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and why do you want an Action and an ActionListener on the same button in the first place?
 
Ash Kondhalkar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In our application, the actions on buttons are handled in the framework class, here in we are using SetAction!
Now due to this we are facing one issue, to overwrite that, we have added one action listener for the buttons.

Now what is happening is, the action listener action performed method is getting called first and then the actionPerformed method of Action class is getting called. I was surprised to see this as, the setAction was done on the button first and action listener was added later.


Regards
Ashwin
 
Campbell Ritchie
Marshal
Posts: 64705
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read Maneesh Godbole's reply again. It depends how long the events take to travel through the system; if you want to overwrite or override the Action I think you should remove it and only have the Listener.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!