Converting a String to Color in Java -


In .NET you can accomplish something like this:

  color yellow = Color Senam ("yellow");  

Is there a way to do this in Java without reflection?

PS: I'm not asking for alternative ways of storage / loading colors. I want to know whether this is possible or not.

Use reflection color Reach a stable member of the class .

  color color; Try {field field = Class.forName ("java.awt.Color"). GetField ("Yellow"); Color = (color) field.get (null); } Hold (exception e) {color = zero; // not defined}  

Comments