这是使用滚动条的颜色选择器。我收到的错误是:使用颜色构造函数在Label上设置setBackground。 错误: 此类中的构造函数颜色不能应用于给定类型。 (int,int,int)除了参数之外没有参数。
import java.awt.*;`
import java.awt.event.*;
public class Color extends Frame implements AdjustmentListener
{
static Label lb1,lred,lgreen,lblue;
static TextField tf1,tf2,tf3;
static Scrollbar sb,sb1,sb2;
static Panel p_main,p1,p2,p3;
static Color c;
public static void main(String args[])
{
lb1 = new Label("");
lred = new Label("Red");
lgreen = new Label("Green");
lblue = new Label("Blue");
tf1 = new TextField(20);
tf2 = new TextField(20);
tf3 = new TextField(20);
sb = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255);
sb1 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255);
sb2 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255);
c = new Color();
p_main = new Panel();
p1 = new Panel();
p2 = new Panel();
p3 = new Panel();
c.setLayout(new GridLayout(4,3));
p1.setLayout(new GridLayout(1,1));
p1.add(lb1);
p2.setLayout(new GridLayout(1,3));
p2.add(lred);
p2.add(lgreen);
p2.add(lblue);
p3.setLayout(new GridLayout(1,3));
p3.add(tf1);
p3.add(tf2);
p3.add(tf3);
p_main.setLayout(new GridLayout(3,3));
p_main.add(p1);
p_main.add(p2);
p_main.add(p3);
c.add(p_main);
c.add(sb);
c.add(sb1);
c.add(sb2);
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
int red,green,blue;
red = sb.getValue();
green = sb1.getValue();
blue = sb2.getValue();
lb1.setBackground(new Color(red,green,blue));
lred.setBackground(new Color(red,0,0));
lgreen.setBackground(new Color(0,green,0));
lblue.setBackground(new Color(0,0,blue));
Integer ival = new Integer(red);
String str1 = ival.toString();
tf1.setText(str1);
Integer iv = new Integer(green);
String str2 = iv.toString();
tf1.setText(str2);
Integer iva = new Integer(red);
String str3 = iva.toString();
tf1.setText(str3);
}
}
答案 0 :(得分:0)
您已经命名了自己的类Color,并且此类中唯一的构造函数是空构造函数,它是由java编译器默认创建的。您必须将自己的类重命名为其他类。然后你可以尝试Swing或awt Color。