Adjustment Listener

ScrollBar
    Public void adjustmentValueChanged(ActionEvent e)
    {
        ----
        ----
    }

Applet : Three ScrollBars each displaying colour value for r, g, and b respectively. On changing these three values, the TextField as well as the Background color is changed to that color and at the same time color code is displayed in TextField.
ScrollBar sb1, sb2, sb3;
Sb1 = new ScrollBar(ScrollBar.VERTICAL,
    0,    starting point
    1,     increment
    0,     minimum value
    255,)    maximum value








 import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class FrameScroll extends Applet implements AdjustmentListener
{
    Frame f;
    TextField tf1;
    Scrollbar sb1, sb2, sb3;

    public void init()
       {
        f = new Frame("Frame With Scroll");
        tf1 = new TextField(20);
        sb1 = new Scrollbar(Scrollbar.VERTICAL,0,1,0,255);
        sb2 = new Scrollbar(Scrollbar.VERTICAL,0,1,0,255);
        sb3 = new Scrollbar(Scrollbar.VERTICAL,0,1,0,255);

        add(sb1);
        add(sb2);
        add(sb3);
        add(tf1);
      
//        add.setLayout(new FlowLayout());
        sb1.addAdjustmentListener(this);
        sb2.addAdjustmentListener(this);
        sb3.addAdjustmentListener(this);
    }
    public void adjustmentValueChanged(AdjustmentEvent e)
    {
        repaint();
    }
    public void paint(Graphics g)
    {
        int a = sb1.getValue();
        int b = sb2.getValue();
        int c = sb3.getValue();
        Color d = new Color(a,b,c);
        setBackground(d);
        tf1.setText(a+" "+b+" "+c);
        tf1.setBackground(d);
    }
}

Click new -> File -> html    and save this file as FrameScroll.html

<BODY>

<Applet code=FrameScroll.class height=100 width=400 >

</Applet>

</BODY>

Applet : Take color value in three TextField for r, g, and b respectively. On clicking “SHOW COLOR” Button, change the Background color to that color.







import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class FrameColors extends Applet implements ActionListener
{
    Frame f;
    TextField tf1, tf2, tf3;
    Button b1;

    public void init()
       {
        f = new Frame("Frame With Scroll");
        tf1 = new TextField(5);
        tf2 = new TextField(5);
        tf3 = new TextField(5);
        b1 = new Button("Show Color");
       
        add(tf1);
        add(tf2);
        add(tf3);
        add(b1);
       
//        add.setLayout(new FlowLayout());
        tf1.addActionListener(this);
        tf2.addActionListener(this);
        tf3.addActionListener(this);
        b1.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e)
    {
        repaint();
    }
    public void paint(Graphics g)
    {
        String x = tf1.getText();
        String y = tf2.getText();
        String z = tf3.getText();

        int a = Integer.parseInt(x);
        int b = Integer.parseInt(y);
        int c = Integer.parseInt(z);
       
        Color d = new Color(a,b,c);
        setBackground(d);
    }
}

Click new -> File -> html    and save this file as FrameColors.html

<BODY>

<Applet code=FrameColors.class height=100 width=400 >

</Applet>

</BODY>