File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
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: 1122
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: 2271

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: 8412

(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: 3134

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?
It's not a secret anymore!