Java Example Program / Sample Source Code
import java.awt.Color;
import java.lang.reflect.Field;
public class RetrieveColorByName {
public static void main(String[] args) {
try {
// Find the field and value of colorName
Field field = Class.forName("java.awt.Color").getField("blue");
System.out.println((Color) field.get(null));
} catch (Exception e) {
e.printStackTrace();
}
}
} |
|
|