Java examples for 2D Graphics:Color RGB
Retrieving a Predefined Color by Name
import java.awt.Color; import java.lang.reflect.Field; public class Main { public Color getColor(String colorName) { try {/*from www .j a v a2s . c o m*/ // Find the field and value of colorName Field field = Class.forName("java.awt.Color").getField(colorName); return (Color) field.get(null); } catch (Exception e) { return null; } } }