| Author |
what's the difference between action objects and actionlisteners?
|
budsy remo
Ranch Hand
Joined: Sep 20, 2008
Posts: 103
|
|
|
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
Joined: Oct 13, 2005
Posts: 32599
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
|
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
Joined: Jan 20, 2009
Posts: 168
|
|
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.
|
SCJD 6, Baroque Potion, Intermediate Java, G+
|
 |
budsy remo
Ranch Hand
Joined: Sep 20, 2008
Posts: 103
|
|
|
really want an example though . Example in the link is not good enough.
|
 |
Rob Camick
Ranch Hand
Joined: Jun 13, 2009
Posts: 1786
|
|
|
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
Joined: Oct 13, 2005
Posts: 32599
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
You mean using horizontalAction instead of verticalAction in the second part of the initialization?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
|
Something like that. I have a corrected version here.
|
 |
 |
|
|
subject: what's the difference between action objects and actionlisteners?
|
|
|