JColorChooser.showDialog(tEkran, "Select a Color", selectedColorBG);
选择一种颜色后,我需要将其转移到3变量。像这样:
colorR = selectedColorBG.getR
colorG = selectedColorBG.getG
colorB = selectedColorBG.getB
有没有办法做到这一点?
答案 0 :(得分:4)
JColorChooser
有一个getColor
方法,返回Color
,其中分别包含方法getRed
,getGreen
和getBlue
答案 1 :(得分:1)
您必须处理返回值:
Color selectedColor = JColorChooser.showDialog(tEkran, "Select the color", initialColor);
int red = selectedColor.getRed();
int green = selectedColor.getGreen();
int blue = selectedColor.getBlue();
答案 2 :(得分:0)
查看java.awt.Color
documentation会回答您的问题:
int getAlpha()
Returns the alpha component in the range 0-255.
int getBlue()
Returns the blue component in the range 0-255 in the default sRGB space.
int getGreen()
Returns the green component in the range 0-255 in the default sRGB space.
int getRed()
Returns the red component in the range 0-255 in the default sRGB space.