pyang051597
asked on
A quick question
Greetings,
How do I convert a string getParameter("white") to a class Color instance?
thanks,
How do I convert a string getParameter("white") to a class Color instance?
thanks,
Hmm... how about a long if, else if statement to compar the colors?
There are only about 13 of them.
There are only about 13 of them.
ASKER
Can you give me an example how to use decode(string) please?
Thanks,
btw, sailwind, I am not going to do a loop 13 times, sorry:)
Thanks,
btw, sailwind, I am not going to do a loop 13 times, sorry:)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
ASKER
I found a way to do this:
public static Color convertStringToColor(Strin g aString) {
try {
return (Color)Class.forName("java .awt.Color ").getFiel d(aString) .get(null) ;
} catch(Throwable e) {
System.err.println(e);
return null;
}
no loop needed!
public static Color convertStringToColor(Strin
try {
return (Color)Class.forName("java
} catch(Throwable e) {
System.err.println(e);
return null;
}
no loop needed!
public static Color decode(String nm) throws NumberFormatException;
the Color constructor takes an RGB value:
public Color(int r, int g, int b); or public Color(int rgb);
-hope this helps