It's not a secret anymore!
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Did i use awt components? 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 "Did i use awt components?" Watch "Did i use awt components?" New topic

Did i use awt components?

Bernd Wollny
Ranch Hand

Joined: May 15, 2006
Posts: 59

Hi guys,

i was searching through my code by looking for "java.awt.Component". And, what the hell, i found one reference. I found it when i was overriding JTable and
it's method "prepareRenderer(TableCellRenderer, int, int)" which returns java.awt.Component, so i did use it right? I mean i was unsing a swing component which uses
awt components.

But, what now? Will i fail? Can i retake the assignment, just deleting this part of code?

Thanks and greetz

Roel De Nijs

Joined: Jul 19, 2004
Posts: 8359

Did you not use any layout managers? These are also awt components. As long as you use awt components which does not have a swing alternative you are fine, so don't use TextField, but use JTextField.
So you would not fail for overriding a method which returns Component. The Component class is even the parent class of a lot of swing classes (e.g. JTextField, JButton,...)

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

first of all, even JComponent is-a awt.component.

this method return indeed a component reference, but as the javadoc
say it may be a Jcomponent (remember you can reference a subclass
with a variable of type superclass)

besides, all swing component use awt component internally, the important
thing is that the high level components are Jcomponent.
what's going on inside shouldn't matter.
so to sum up, i don't think you'll fail on that..

Bernd Wollny
Ranch Hand

Joined: May 15, 2006
Posts: 59

Ok, puuuuhh....i am using layout manager, but as the FAQ states here, it is ok because they do not extend java.awt.Component. But i am using the java.awt.Component directly in my class, so i was wondering if it is prohibited...

Roel: thanks for changing my headline, was the first shock...
I agree. Here's the link:
subject: Did i use awt components?
It's not a secret anymore!