当前位置: 首页>>代码示例>>Java>>正文


Java Color.getColor方法代码示例

本文整理汇总了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;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:54,代码来源:Colors.java


注:本文中的java.awt.Color.getColor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。