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 Use javax.swing.Action instead? 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 "Use javax.swing.Action instead?" Watch "Use javax.swing.Action instead?" New topic
Author

Use javax.swing.Action instead?

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 724
Hi,
I just come across javax.swing.Action. It extends ActionListener in java.awt.
For the exam, should I use Action intead of ActionListener?
In study guide, the example code uses ActionListener too.
But the exam requires Swing component.

Which one should I use then? Action or ActionListener?
Thanks in advance.
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Himai Minh wrote:Which one should I use then? Action or ActionListener?


Well, you can use whichever you prefer. You just can't use classes of the java.awt package that have corresponding ones in the java.swing package. For instance, you can't use java.awt.Button, since there's javax.swing.JButton. But there's no problem in using java.awt.event.ActionListener.

Either Action or ActionListener are fine.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5147
    
  12

(As always) I agree with my good buddy Roberto.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2247
    
    7

Damn Roberto beat me to the reply

Yes Roberto is right, either one is fine. Action is a class, need to extend AbstractAction. ActionListener is an interface, implements it. Yet whatever you choose, be consistent.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
 
Don't get me started about those stupid light bulbs.
 
subject: Use javax.swing.Action instead?
 
Similar Threads
Polymorphism or conditionals ?
should be declared abstract?
How to handle many events ?
Event Binding in Java ?
O-O event handling..