import java.awt.*; import java.applet.*; public class ColorTest extends Applet { Panel back_color; ColorControls back_red, back_green, back_blue; public void init() { setLayout(new GridLayout(4,1,10,10)); back_color= new Panel(); back_color.setBackground(Color.white); add(back_color); back_red= new ColorControls(this, "red", 255); back_green= new ColorControls(this, "green", 255); back_blue= new ColorControls(this, "blue", 255); add(back_red); add(back_green); add(back_blue); } public Insets insets() { return new Insets(10,10,10,10); } public void update() { Color c; c= new Color(back_red.bar.getValue(), back_green.bar.getValue(), back_blue.bar.getValue()); back_color.setBackground(c); System.out.println("red "+back_red.bar.getValue()+" green "+back_green.bar.getValue()+" blue "+back_blue.bar.getValue()); } } //-----------another class definition---------------------------- class ColorControls extends Panel { ColorTest outerparent; //reference to parent class Scrollbar bar; Label display_val; ColorControls(ColorTest target, String s, int val) { this.outerparent= target; setLayout(new GridLayout(1,3,10,10)); bar= new Scrollbar(Scrollbar.HORIZONTAL, val, 0, 0, 255); display_val= new Label(String.valueOf(val), Label.RIGHT); this.add(new Label(s, Label.RIGHT)); this.add(display_val); this.add(bar); } public Insets insets() { return new Insets(10,10,0,0); } public boolean handleEvent(Event evt) { if (evt.target instanceof Scrollbar) { int x= ((Scrollbar)evt.target).getValue(); this.display_val.setText(String.valueOf(x)); outerparent.update(); return true; } else return false; } } //end of ColorControls class