This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes [SWING - GUI]: Action vs ActionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "[SWING - GUI]: Action vs ActionListener" Watch "[SWING - GUI]: Action vs ActionListener" New topic
Author

[SWING - GUI]: Action vs ActionListener

Kim Lauwers
Ranch Hand

Joined: Sep 23, 2005
Posts: 31
What the difference between the two?
Which one should i favor?

Here what I think / know

ActionListener:
---------------
Action:
-------
  • Is an extension of the ActionListener
  • Abstraction of a command, where no UI component is linked at.
  • You can use different UI components with the same action.
  • Pays the price on memory and performance.


  • I always use actions and this because the assignment says:
    Your user interface should be designed with the expectation of future functionality enhancements, and it should establish a framework that will support this with minimal disruption to the users when this occurs.

    So action are the best I think.


    Or have I a wrong vision?

    thanks,
    Kim


    Programming today is a race between Software Engineers striving to build bigger and better idiot-proof Programs, and the Universe trying to produce bigger and better idiots.<br />So far, the Universe is winning!
    Jeffry Kristianto Yanuar
    Ranch Hand

    Joined: Oct 01, 2007
    Posts: 759
    I think most of the candidates use ActionListener. You just decide how to use the ActionListener.

    I implement inner classes that implements ActionListener such as BookButtonListener, SearchButtonListener, ExitButtonListener, etc. Judging from its name, you can figure out what the functionality of these classes.

    So I think use ActionListener is the best approach.

    Good Luck !!!

    Jeffry Kristianto Yanuar (Java Instructor)
    SCJP 5.0, SCJA, SCJD (UrlyBird 1.3.2) --> Waiting for the result
    [ November 28, 2008: Message edited by: Jeffry Kristianto Yanuar ]
    Kim Lauwers
    Ranch Hand

    Joined: Sep 23, 2005
    Posts: 31
    Originally posted by Jeffry Kristianto Yanuar:
    I think most of the candidates use ActionListener. You just decide how to use the ActionListener.

    I implement inner classes that implements ActionListener such as BookButtonListener, SearchButtonListener, ExitButtonListener, etc. Judging from its name, you can figure out what the functionality of these classes.



    Thanks for the reply. I use the same kind of namingconvention as you, but I never user inner classes. A always create a new class/file. This is my personnal favor, but I don't know if there is another reason to use inner classes or not.

    Greetz,
    Kim
    Alecsandru Cocarla
    Ranch Hand

    Joined: Feb 29, 2008
    Posts: 158
    I use actions as much as I can. They are easier to maintain.

    You can set the same action for more components (e.g. a button and a menu item). You can do the same thing with ActionListeners, but in this case you cannot create anonymous classes, you have to create a new listener class for each action.

    You can already set from the action the name of the action, the mnemonic and the accelerate key (if any). So you don't have to define these for every button.

    For me, this leads to much clearer code (having everything in the same place). The performance hit... what performance hit when you only have something like 3-4 actions in the whole application?


    SCJP 1.4 100%
    SCJD 99.5%
    Jeffry Kristianto Yanuar
    Ranch Hand

    Joined: Oct 01, 2007
    Posts: 759
    OK, whatever you do, just be sure to document your decision, in this assignment, there is no the best solution. remember, simplicity is the key.

    My assignment said that the code must readily understand by junior programmer, so I think ActionListener is easy to understand by junior programmer.

    Good luck and wish me luck too !!!

    Jeffry Kristianto Yanuar (Java Instructor)
    SCJP 5.0, SCJA, SCJD (UrlyBird 1.3.2) --> Waiting for the result
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: [SWING - GUI]: Action vs ActionListener
     
    Similar Threads
    Polymorphism or conditionals ?
    Action Interface
    How to get selected value from struts dropdown list?
    DAO Design Question
    what's the difference between action objects and actionlisteners?