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

Java Reflection

 
simonph
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I am facing a problem. I have an XML which contains tags
like JPanel,JTextField,JButton with attributes for creating UI screen. I am reading this XML file and creating objects using reflection and storing in an Object array. Now when I want to access the methods of JBtton,JTextField... I need to downcast it dynamically into its appropriate class. This is possible using instanceof operator. I need to avoid using if-else statements as I need to handle many swing components. Can I somehow dynamically downcast it, pls help.
Thnx in advance for the help
Regards
Simon
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings Simon,
Welcome to JavaRanch, the absolute best site on the www for Java information. We don't have many rules around here, but we do have one. Please change your display name to a first and last name to conform with the JavaRanch Naming Policy. You can change it here:
Change your display name.
Michael Morris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic