當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。