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 Is it a Swing component? 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 "Is it a Swing component?" Watch "Is it a Swing component?" New topic
Author

Is it a Swing component?

Matt Pavlovich
Ranch Hand

Joined: Aug 14, 2010
Posts: 98
Hey everyone,

I know a while ago I asked about this line of the instructions: "[The User Interface] must be composed exclusively with components from the Java Foundation Classes (Swing components)." I was told this means that I should not use a .awt component if a .swing component exists. I did not see any Swing components that could be used instead of what I used, but I thought I would run it by you guys here to make sure I have not imported something to use in my classes that should not be. The events and layouts are no doubt good to go, but I wanted to check on Dimension, Toolkit, and Window.

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.BorderLayout;
import java.awt.FlowLayout;

Thanks, guys.
Matt



Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Dimension and Toolkit aren't Components -- they don't inherit from java.awt.Component, the superclass of all AWT and Swing components.

And there is a javax.swing.JWindow.


luck, db
There are no new questions, but there may be new answers.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5139
    
  12

Matt Pavlovich wrote:I did not see any Swing components that could be used instead of what I used

Did you not use JTextField, JLabel, JButton,...?

Matt Pavlovich wrote:The events and layouts are no doubt good to go, but I wanted to check on Dimension, Toolkit, and Window.

Did you check the javadoc of these classes? That's what we have to do too e.g. Window. This class has a subclass JWindow (so you know that's a swing class). In one of my utility methods I used Window (because you should use the most general class (even better would be an interface) when possible.


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

Joined: Dec 28, 2007
Posts: 2258
    
    3

And just to complement what's been said here, you are allowed to use AWT components/classes as long as there isn't a corresponding one in the Swing framework. One example is the java.awt.event.ActionListener class.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Matt Pavlovich
Ranch Hand

Joined: Aug 14, 2010
Posts: 98
Guys,

Yes, the JWindow was right in front of my face... And not to worry, Roel, I did use JButton, JTextField, etc.

Its all clear now...thanks guys.
Matt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it a Swing component?
 
Similar Threads
Exclusively Swing
can I use AWT?
NX: Use of awt components for user interface
Simple GUI question
A newbie to MVC Architecture,components in JFC