0

This is an color picker using scrollbar. I am getting errors namely: setBackground on Label using color constructor. ERRORS: constructor color in this class cannot be applied to given types. (int,int,int) no arguments excepted.

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);
}
   }
Prasath
  • 1,233
  • 2
  • 16
  • 38
Honey
  • 19
  • 10
  • 3
    It's because your class name `Color` shadows `java.awt.Color`. Change the name of your class. – Vince Jun 24 '17 at 18:02
  • 1) Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT components in favor of Swing. 2) See [Detection/fix for the hanging close bracket of a code block](http://meta.stackexchange.com/q/251795/155831) for a problem I could no longer be bothered fixing. 3) The problem @VinceEmigh highlights could be solved by using a meaningful name fot the custom class. E.G. `ColorLabel`.. – Andrew Thompson Jun 25 '17 at 07:59
  • Thankyou so much, the name of the class and label is settled but i still cannot get the background color. – Honey Jun 25 '17 at 09:21
  • Swing is awlays a better option. Thankyou again. – Honey Jun 25 '17 at 09:37

1 Answers1

0

You have named your own class Color and the only constructor in this class is the empty constructor, which is created by default by java compiler. You have to rename your own class to something else. Then you can try both Swing or awt Color.