File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes what's the difference between action objects and actionlisteners? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "what Watch "what New topic
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: 38517
    
  23
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: 19684
    
  20

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38517
    
  23
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: 172

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, OCPJP7, Baroque Potion, 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: 2180
    
    7
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: 38517
    
  23
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: 19684
    
  20

You mean using horizontalAction instead of verticalAction in the second part of the initialization?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38517
    
  23
Something like that. I have a corrected version here.
 
Consider Paul's rocket mass heater.
 
subject: what's the difference between action objects and actionlisteners?