I am using GridWorld in my AP Computer Science class, and part of what we are doing is changing the color of the bug (an object). I have found a very basic way to do this but am trying to incorporate strings to allow the user to type in what color he would like the bug to be instead of having to put in number values for RGB. I am able to get the string value to be the color that I want, by typing in, "red" and having the string store that. But how would I get that string to translate into the color? I'm not really sure if I worded this clearly enough but I have attached my code so hopefully someone will understand and can help.
Color red = new Color (255, 0, 0);
Color green = new Color (0, 255, 0);
Color blue = new Color (0, 0, 255);
System.out.println("What color would you like the first bug to be? (red, green, blue)");
String name = "color1";
String color1 = keyboard.next();
if (color1 == "red")
{
world.add (new Location (bugx1, bugy1), new Bug(red));
}
if (color1 == "blue")
{
world.add (new Location (bugx1, bugy1), new Bug(blue));
}
if (color1 == "green")
{
world.add (new Location (bugx1, bugy1), new Bug(green));
}