In order to save Color attributes of a graphical object in my application, I saved the string representation of this Color in a data file.
For instance, for red I save: java.awt.Color[r=255,g=0,b=0]
.
How can I convert this string representation into a Color so that I can use it again after loading my data file ?
Thank you.
Stephan's answer helped me with this. However, I found that I needed to add a 'true' to the syntax in order to restore the color.
The easiest thing is to rethink the way you store the string representation. Get rid of all the labeling, and just store red as the string "0xFF0000". Then you can easily parse that string to get the single value for rgb, and send it to the Color constructor.
The alternative is to parse the more complicated string as you are now saving it "java.awt.Color[r=255,g=0,b=0]".
You can see the constructors for Color here: http://java.sun.com/javase/6/docs/api/ (search "all classes" for Color).
Peter