This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Getting component type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting component type" Watch "Getting component type" New topic
Author

Getting component type

Barry Brashear
Ranch Hand

Joined: Jun 05, 2001
Posts: 303
If an object of type componet is coming into a method, what is the best
way to detemine it's type, such as checking if it's a JInternalFrame, or
JPanel?

Thanks.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
You mean, if you have an reference, of compile-time type Component, how do you find out the run-time type of the object to which it points?

Usually, you would use the "instanceof" operator.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Lionel Badiou
Ranch Hand

Joined: Jan 06, 2005
Posts: 140
Hello Barry,

You may try .

Hope that helps,


Lionel Badiou
CodeFutures Software
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
You can also use reflection:

Of course, this may be of only limited use depending what you need to do with this information once you have it.

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting component type