JColorChooser.showDialog(tEkran, "Select a Color", selectedColorBG);
選擇顏色後,我需要將其轉換爲3變量。像這樣:如何從顏色變量獲取RGB值
colorR = selectedColorBG.getR
colorG = selectedColorBG.getG
colorB = selectedColorBG.getB
有沒有辦法做到這一點?
JColorChooser.showDialog(tEkran, "Select a Color", selectedColorBG);
選擇顏色後,我需要將其轉換爲3變量。像這樣:如何從顏色變量獲取RGB值
colorR = selectedColorBG.getR
colorG = selectedColorBG.getG
colorB = selectedColorBG.getB
有沒有辦法做到這一點?
JColorChooser
有getColor
方法返回一個Color
它擁有一些方法getRed
,getGreen
和getBlue
分別
你必須處理的返回值:
Color selectedColor = JColorChooser.showDialog(tEkran, "Select the color", initialColor);
int red = selectedColor.getRed();
int green = selectedColor.getGreen();
int blue = selectedColor.getBlue();
謝謝,很多... – Murat
一看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.
謝謝。很多... – Murat
你們倆呃在發佈這個問題之前查看文檔? http://docs.oracle.com/javase/7/docs/api/java/awt/Color.html –
你甚至看過Java API嗎? http://docs.oracle.com/javase/7/docs/api/javax/swing/JColorChooser.html#getColor%28%29 – Brian