📄 colorbar.java
字号:
import java.awt.*;
import java.awt.event.*;
public class ColorBar extends Scrollbar {//颜色调整
/**
*
*/
private static final long serialVersionUID = 1L;
public ColorBar( ){
super(Scrollbar.HORIZONTAL,0,40,0,295);
this.setUnitIncrement(1);
this.setBlockIncrement(50);
}
public static void main(String[] args) {
ColorPanel col=new ColorPanel();
col.setVisible(true);
}
}
class ColorPanel extends Panel implements AdjustmentListener, ActionListener{
/**
*
*/
Button b=new Button("确定");
private static final long serialVersionUID = 1L;
Scrollbar red=new ColorBar();
Scrollbar green=new ColorBar();
Scrollbar blue=new ColorBar();
Canvas my=new Canvas();//用于反映颜色变化的画布
Color color;//用于供调用者获取颜色
public ColorPanel(){
add("South",b);
b.addActionListener(this);
Panel x=new Panel();
x.setLayout(new GridLayout(3,2,1,1));
x.add(new Label("red"));x.add(red);
x.add(new Label("green"));x.add(green);
x.add(new Label("blue"));x.add(blue);
setLayout(new GridLayout(2,1,5,5));
add(my);
add(x);
red.addAdjustmentListener(this);
green.addAdjustmentListener(this);
blue.addAdjustmentListener(this);
}
//滚动条调整时,根据调整值改变画布的颜色
public void adjustmentValueChanged(AdjustmentEvent e) {
// TODO Auto-generated method stub
int v1,v2,v3;
v1=red.getValue();
v2=green.getValue();
v3=blue.getValue();
color=new Color(v1,v2,v3);
my.setBackground(color);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getActionCommand( ).equals("确定")){
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -