// This applet uses a scrollbar to control the size of a circle.
// The radius of the circle is determined by the value of the
// scrollbar.

// To run this applet, click on circles.html.

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class circles extends Applet implements AdjustmentListener
{
    private int radius;
    Scrollbar sizes;
    private circle first, second;
    private point center;
    Graphics page;

    public void init ()
    {
        setBackground (Color.cyan);
        center = new point (150, 100);
        radius = 10;
        first = new circle (center, radius);
        setLayout (null);
        sizes = new Scrollbar (Scrollbar.HORIZONTAL, 0, 1, 0, 50);
        sizes.addAdjustmentListener (this);
        sizes.setBounds (50, 200, 200, 15);
        add (sizes);
        page = getGraphics ();
    }

    public void adjustmentValueChanged (AdjustmentEvent event)
    {
        if (event.getAdjustable () == sizes)
        {
            page.setColor (Color.cyan);
            first.drawCircle (page);
            radius = sizes.getValue ();
            second = new circle (center,radius);
            page.setColor (Color.blue);
            second.drawCircle (page);
            first = second;
        }
    }

} // class circles

class point
{
     private int x, y;

    point (int x, int y)
    {
        this.x = x;
        this.y = y;
    }

    int get_x ()
    {return x;}

    int get_y ()
    {return y;}

    void set_xy (int x, int y)
    {
        this.x = x;
        this.y = y;
    }

}// class point

class circle
{
    private point center;
    private int radius;

    circle (point center, int radius)
    {
        this.center = center;
        this.radius = radius;
    }

    public void drawCircle (Graphics page)
    {
        int x, y;
        x = center.get_x ();
        y = center.get_y ();
        page.drawOval (x-radius, y-radius, 2*radius, 2*radius);
    }
} // class circle