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

what's the difference between action objects and actionlisteners?

 
budsy remo
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please explain that how is the actionlistener interfaces different from action interfaces . I am talking more in the terms of use , that is what to use and when to use?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor gave a nice example recently, but I can't seem to find it now. I found this post by David Byron, which has a link to the Java™ tutorials on.
An Action incorporates an ActionListener, as well as a Map which you can put additional details in. See what you can get from the documentation, and come back if you don't understand something.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure it was me? It sounds like something I could have posted but I can't find it in my own post history.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pretty sure it was you, Rob, but couldn't find anything on a search. I did write an example myself at home to try it out, but can't seem to find it. this is what comes from being a two-PC family; I have probably left it at home. I might be able to look later.
 
David Byron
Rancher
Posts: 175
Clojure Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
budsy remo wrote:Can anyone please explain that how is the actionlistener interfaces different from action interfaces . I am talking more in the terms of use , that is what to use and when to use?

The main decision point is whether you want an object that can respond in the same way to events kicked up by several different UI components.

For example, if you have (a) a button, (b) a menu item, and (3) a custom component, and if they are all supposed to bear the same name and do the same thing, then an Action will allow you to define the Title, Icon, Accelerator or Mnemonic, and functionality in just one place.

Think of it as a listener on steroids.
 
budsy remo
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
really want an example though . Example in the link is not good enough.
 
Rob Camick
Ranch Hand
Posts: 2564
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the Swing tutorial. There is a section on "How to Use Actions" and "How to Write an Action Listener". Both contain examples and explanations.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I, last week wrote:Rob Spoor gave a nice example recently, but I can't seem to find it now. . . ..
But I used an Action (in the form of an AbstractAction) in another post. See if you can find my silly mistake
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean using horizontalAction instead of verticalAction in the second part of the initialization?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like that. I have a corrected version here.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic