aspose file tools*
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
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: 594
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: 2247

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: 4913
    
  10

(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: 1966
    
    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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Use javax.swing.Action instead?
 
Similar Threads
How to handle many events ?
should be declared abstract?
O-O event handling..
Polymorphism or conditionals ?
Event Binding in Java ?