Hi folks, I have to answer the following question:
"Write an applet which contains a panel whose background colour varies as the elevators of three Scrollbar objects are varied. Each Scrollbar object affects one colour constituent."
I think I'm pretty close, but I can't figure out why only one of the scrollbars changes colour. They should change red, green, and blue respectively.
I'd be really grateful for any help on this one. Thanks!
/*applet which demonstrates the use of a canvas*/
import java.awt.*;
public class u extends java.applet.Applet
{
Canvas can;
Scrollbar s;
Color bg;
int b;
int g;
int r;
public void init()
{
setLayout(new GridLayout(1, 2, 10, 10));
bg = new Color(0, 0, 255);
can = new Canvas();
s = new Scrollbar(Scrollbar.VERTICAL, 0, 0, 0, 255);
can.setBackground(bg);
add(can);
add(s);
bg = new Color(0, 255, 0);
s = new Scrollbar(Scrollbar.VERTICAL, 0, 0, 0, 255);
can.setBackground(bg);
add(s);
bg = new Color(255, 0, 0);
s = new Scrollbar(Scrollbar.VERTICAL, 0, 0, 0, 255);
can.setBackground(bg);
add(s);
}
public boolean handleEvent(Event evt)
{
if (evt.target instanceof Scrollbar)
{
r = s.getValue();
g = s.getValue();
b = s.getValue();
bg = new Color(r, g, b);
can.setBackground(bg);
can.repaint();
}
return true;
}
}