?? e584. retrieving a predefined color by name.txt
字號:
The Color class contains a number of predefined colors such as red and green. This example demonstrates how to retrieve one of these predefined colors using a string. For example, the predefined color java.awt.Color.red could be retrieved with the string "red".
// Returns a Color based on 'colorName' which must be one of the predefined colors in
// java.awt.Color. Returns null if colorName is not valid.
public Color getColor(String colorName) {
try {
// 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;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -