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

Getting component type

 
Barry Brashear
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lionel Badiou
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Barry,

You may try .

Hope that helps,
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic