Java Color from String string2color(String str)

Here you can find the source of string2color(String str)

Description

Insert the method's description here.

License

Open Source License

Parameter

Parameter Description
str java.lang.String

Return

java.awt.Color

Declaration

public static java.awt.Color string2color(String str) 

Method Source Code


//package com.java2s;
import java.awt.Color;

public class Main {
    /**//from  w  w w .  jav a  2s  . co m
     * Insert the method's description here.
     * Creation date: (23.4.2001 18:52:04)
     * @return java.awt.Color
     * @param str java.lang.String
     */
    public static java.awt.Color string2color(String str) {
        int rgb = Integer.parseInt(str);
        // !!! add more or use flyweight
        switch (rgb) {
        case 0x000000:
            return Color.black;
        case 0x0000ff:
            return Color.blue;
        case 0x00ff00:
            return Color.green;
        case 0xff0000:
            return Color.red;
        case 0xffffff:
            return Color.white;
        default:
            return new Color(rgb);
        }

    }
}

Related

  1. str2Color(String s, Color defaultValue)
  2. string2Color(String stringColor)
  3. stringToColor(final String s)
  4. stringToColor(final String value)
  5. stringToColor(String color)