So, I am making a small Java Game as a school project and want to return an image, which should be in a HashMap. In the method I call, i want to give a java.awt.Color as a parameter and make a switch statement on it.
(Note: All colors going INTO the function are default Colors like "Color.red" or "Color.green"!)
I already tried to do it with the RGB value of the Color, but that doesn't work.
Heres the NOT WORKING code:
private static HashMap<Color, Image> blocks_hash;
public static void setBlock(Color color, Image image) { blocks_hash.put(color, image); }
public static Image getBlock(Color color) {
if(blocks_hash.containsKey(color))
return blocks_hash.get(color);
else
switch (color.getRGB()) {
case Color.red.getRGB():
return getBlocks().getSubimage(0, 0, 60, 60);
}
return null;
}