• Post Reply Bookmark Topic Watch Topic
  • New Topic

setAction and addActionListener  RSS feed

 
Ash Kondhalkar
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
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 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.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • 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: 55772
163
  • 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!