Hey everyone. I could use some serious help with a Java method that I have to construct for my CMIS class. Basically, I have to develop a static method that has two arrays in it, one a String array that has values of colors; the other, a Color array that has the proper names for the colors. I have to take a user inputted String and compare it the the Color array and when a match is found, return the RGB integer values of the color as a 3 value int array. I have placed my code below for what I have. I believe that everything is correct except for the if statement that compares the String to the Color object. All help is greatly appreciated. Thanks!
import java.awt.Color;
/**
*
* @author johnkershaw
*/
public class homework7 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
public static int[] getColors(String stringColor) {
Color[] standardColors = new Color[] {
Color.BLACK, Color.BLUE, Color.CYAN,
Color.DARK_GRAY, Color.GRAY, Color.GREEN, Color.LIGHT_GRAY,
Color.MAGENTA, Color.ORANGE, Color.PINK, Color.RED, Color.WHITE,
Color.YELLOW};
String[] inputColors = {"BLACK", "BLUE", "CYAN", "DARK_GRAY", "GRAY",
"GREEN", "LIGHT_GRAY", "MAGENTA", "ORANGE", "PINK", "RED", "WHITE",
"YELLOW"};
int[] components = new int[3];
//Color color = new Color();
for (int i = 0; i < standardColors.length; i++) {
if (stringColor.equals(standardColors[i].toString()))
//if (Color.stringColor.equals(standardColors[i]))
//standardColors[i] = new Color();
int r = standardColors[i].getRed();
int g = standardColors[i].getGreen();
int b = standardColors[i].getBlue();
components[0] = r;
components[1] = g;
components[2] = b;
}
return components;
}
}