my dog learned polymorphism
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

Use javax.swing.Action instead?

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 1074
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

Joined: Dec 28, 2007
Posts: 2270

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

Joined: Jul 19, 2004
Posts: 7889

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

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
K. Tsang

Joined: Sep 13, 2007
Posts: 3059

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 OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
I agree. Here's the link:
subject: Use javax.swing.Action instead?
jQuery in Action, 3rd edition