Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Is it a Swing component?

 
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



 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • 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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • 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
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic