get String For Color - Java 2D Graphics

Java examples for 2D Graphics:Color String

Description

get String For Color

Demo Code


//package com.java2s;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] argv) throws Exception {
        int c = 2;
        System.out.println(getStringForColor(c));
    }//from ww  w  . j  a va 2 s . c  om

    static Map intToString = new HashMap();

    public static String getStringForColor(int c) {
        String result = (String) intToString.get(new Integer(c));
        if (result != null) {
            return result;
        }
        return getHexForColor(c);
    }

    public static String getHexForColor(int c) {
        return "#"
                + Integer.toHexString((c & 0xffffff) | 0x1000000)
                        .substring(1);
    }
}

Related Tutorials