• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[SWING - GUI]: Action vs ActionListener

 
Kim Lauwers
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
     
    Jeffry Kristianto Yanuar
    Ranch Hand
    Posts: 759
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 31
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 158
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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?
     
    Jeffry Kristianto Yanuar
    Ranch Hand
    Posts: 759
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic