「java储存颜色」java定义颜色
今天给各位分享java储存颜色的知识,其中也会对java定义颜色进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
java里颜色类默认的几种颜色对应的int值是多少?
public final static Color white = new Color(255, 255, 255);
public final static Color lightGray = new Color(192, 192, 192);
public final static Color gray = new Color(128, 128, 128);
public final static Color darkGray = new Color(64, 64, 64);
public final static Color black = new Color(0, 0, 0);
public final static Color red = new Color(255, 0, 0);
public final static Color pink = new Color(255, 175, 175);
public final static Color orange = new Color(255, 200, 0);
public final static Color yellow = new Color(255, 255, 0);
public final static Color green = new Color(0, 255, 0);
public final static Color magenta = new Color(255, 0, 255);
public final static Color cyan = new Color(0, 255, 255);
public final static Color blue = new Color(0, 0, 255);
其值在Color类内部以int的形式存着,24-32位为alpha值,16-23为red,8-15为green,0-7则是blue。默认的alpha值为全1,也就是255,完全不透明。
比如说
public final static Color pink = new Color(255, 175, 175);
表示在其内部颜色的值为255*2^24+255*2^16+175*2^8+175=4294946735
Java中如何将RGB三个颜色的值存放到数组中
先定义一个类:其中三个属性,R、G、B
public class ColorVo{
private int r;
private int g;
private int b;
getter setter
}
然后创建一个 ColorVo 数组
ColorVo[] array = new ColorVo[n];
n表示数组长度。
然后
ColorVo cv = new ColorVo();
cv.setR(1);
cv.setG(2);
cv.setB(3);
array[i] = cv
i表示数组的下表
此时就已经将ColorVo 放入了数组中
用java声明一个颜色类Color
import java.awt.*;
import java.awt.event.*;
public class adjustcolor implements AdjustmentListener, WindowListener {
Frame f=new Frame("调整颜色");
Label l1=new Label("调整滚动条,会改变初始颜色",Label.CENTER);
Label l2=new Label("此处显示颜色值",Label.CENTER);
Label l3=new Label("红",Label.CENTER);
Label l4=new Label("绿",Label.CENTER);
Label l5=new Label("蓝",Label.CENTER);
Scrollbar scr1=new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,265);
Scrollbar scr2=new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,265);
Scrollbar scr3=new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,265);
public adjustcolor(){
f.add(l1);
f.add(l2);
f.add(l3);
f.add(l4);
f.add(l5);
f.add(scr1);
f.add(scr2);
f.add(scr3);
f.setSize(400,350);
f.setVisible(true);
f.addWindowListener(this);
f.setResizable(false);
l1.setBackground(Color.GREEN);
scr1.setBounds(35,225,360,25);
scr2.setBounds(35,255,360,25);
scr3.setBounds(35,285,360,25);
l1.setBounds(0,0,400,200);
l2.setBounds(0,310,400,30);
l3.setBounds(0,225,30,30);
l4.setBounds(0,255,30,30);
l5.setBounds(0,285,30,30);
scr1.addAdjustmentListener(this);
scr2.addAdjustmentListener(this);
scr3.addAdjustmentListener(this);
l1.setBackground(Color.GREEN);
scr1.setBackground(Color.RED);
scr2.setBackground(Color.GREEN);
scr3.setBackground(Color.blue);
}
public void adjustmentValueChanged(AdjustmentEvent e){
int a=scr1.getValue();
int b=scr2.getValue();
int c=scr3.getValue();
l1.setBackground(new Color(a,b,c)) ;
l2.setText("红"+" "+"绿"+" "+"蓝"+" "+a+" "+b+" "+c);
l1.setText(null);
}
public static void main(String[] args){
new adjustcolor();
}
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosed(WindowEvent arg0) {
}
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
}
这是源代码 应该是你想要的
java储存颜色的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java定义颜色、java储存颜色的信息别忘了在本站进行查找喔。