本文整理汇总了Java中java.awt.Color.getColor方法的典型用法代码示例。如果您正苦于以下问题:Java Color.getColor方法的具体用法?Java Color.getColor怎么用?Java Color.getColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Color
的用法示例。
在下文中一共展示了Color.getColor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findColor
import java.awt.Color; //导入方法依赖的package包/类
/**
* Searches for a color with a given name or key, given as a string. The
* color is searched using the following criteria:
* <ul>
* <li> If the name is one of the keys in <tt>getColorMap()</tt> then the
* corresponding key is returned;
* <li> Otherwise, if the name is a system property (recognised by
* <tt>Color.getColor(String)</tt>) then the corresponding color is
* returned;
* <li> Otherwise, if the name is a color key recognised by
* <tt>Color.decode(String)</tt>) then the corresponding color is
* returned;
* <li> Otherwise, if the name is a space-separated sequence of three or
* four byte values standing for the red, green and blue components, and
* optionally an alpha value, then the corresponding color is returned using
* the appropriate <tt>Color</tt> method;
* <li> Otherwise, the color cannot be found and <tt>null</tt> is
* returned.
* </ul>
* @param name the name or key under which the color is sought
* @return the color found for <tt>name</tt>, or <tt>null</tt> if no
* such color is found.
* @see #getColorMap()
* @see Color#getColor(String)
*/
public static Color findColor(String name) {
if (colorMap.containsKey(name)) {
return colorMap.get(name);
}
Color result = Color.getColor(name);
if (result != null) {
return result;
}
try {
return Color.decode(name);
} catch (NumberFormatException exc) {
// proceed
}
// try decompose the color as a sequence of red green blue [alpha]
int[] val = Groove.toIntArray(name);
if (val == null) {
val = Groove.toIntArray(name, ",");
}
if (val != null) {
if (val.length == 3) {
return new Color(norm(val[0]), norm(val[1]), norm(val[2]));
} else if (val.length == 4) {
return new Color(norm(val[0]), norm(val[1]), norm(val[2]),
norm(val[3]));
}
}
return null;
}