Java examples for 2D Graphics:Color String
get String For Color
//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); } }