Let's say I have a
public class things {
String name = new string;
int nr = new nr;
//constructor etc
}
Now let's assume there are already a bunch of instances initialized. let's call them thingA, thingB, thingC (I will need them to be more later...)
I'm having a JFrame where the User can Input a text and the input shall be one of the classes so he could type "thingB", "thingD", ... "thingN"
within an actionPerformed I now want to:
String s = jLabel_1.getText();
and then do sth like.
System.out.println("" + s.nr)
Obviously, that doesn't work since s is a string only containing the value entered in the text-label, so what I wanna do is tell Java that the object's name I'm trying to use is the one saved in 's'. I really tried to look it up but I couldn't find anything except a
Class.forName(String...) option which didn't really work either, respectively I didn't know how to use it.
Class.forName(label.getText())should work if the user enters the full class name. If they don't, you need to concatenate their input with the package name where these classes are located