如何在数组中存储十六进制颜色

时间:2016-06-14 08:33:39

标签: java arrays

如何在私有数组中存储下表中的十六进制颜色?

400 Bad Request - Invalid request body - JSON mapping failed.

颜色的名称存储在公共枚举中。数组也应该是class属性。

Name    R   G   B
BLACK   00  00  00
NAVY    00  00  80
BLUE    00  00  FF

1 个答案:

答案 0 :(得分:2)

您可以使用枚举为您存储值:

public enum COLORS {
    BLACK(0x00, 0x00, 0x00),
    NAVY(0x00, 0x00, 0x80),
    BLUE(0x00, 0x00, 0xFF);

    private int red;
    private int green;
    private int blue;

    private COLORS(int red, int green, int blue) {
        this.red = red;
        this.green = green;
        this.blue = blue;
    }

    public int getRed() {
        return this.red;
    }

    public int getGreen() {
        return this.green;
    }

    public int getBlue() {
        return this.blue;
    }
}