Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it a Swing component?

 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roel De Nijs
Sheriff
Posts: 9828
103
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic