Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a Class Object from the Input from a JTextField.

 
Ryan Perlman
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of going:
MyClass ryan = new MyClass();
can you take the Input from a JTextField and Use it for the Object name of MyClass?
If So where should I continue to look, or what other option do I have.
Ryan Perlman
Having fun while I am learning
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, look at
Class.forName("classname"). This returns a Class object of the type in the argument.
Class myClass = Class.forName("classname")
;
then
Object myNewObject = myClass.newInstance().

Rob
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic