import java.util.Random;
import java.awt.Graphics;
import java.awt.Color;

/**
 * A colored circle has a center, a radius and a color.
 *
 * @version 1.1    March 21, 2002
 * @author Franck van Breugel
 * @see Circle
 */
public class ColoredCircle extends Circle
{
    protected Color color;   // color of this circle

    /*  
     * maximal value to define the amount of red, green and blue
     * in a color.
     */
    private static final int RGB = 255;

    /**
     * Creates a colored circle with the specified center, radius and
     * color.
     * 
     * @param center center of the colored circle.
     * @param radius radius of the colored circle.
     * @param color color of the colored circle.
     */
    public ColoredCircle(Point center, int radius, Color color)
    {
        super(center, radius);
	this.color = color;
    }


    /**
     * Creates a colored circle.  The x-coordinate of its center is 
     * greater than or equal to 0 and smaller than the x-coordinate of
     * the specified point.  The y-coordinate of its center is
     * greater than or equal to 0 and smaller than the y-coordinate of
     * the specified point.  
     *
     * @param corner point that bounds the x- and y-coordinate of the 
     * center of the circle.
     */
    public ColoredCircle(Point corner)
    {
        super(randomCenter(corner), randomRadius(corner));
        Random generator = new Random();
        color = new Color(generator.nextInt(RGB), generator.nextInt(RGB), generator.nextInt(RGB));
    }

    /**
     * Returns a point used in the constructor.
     *
     * @param corner point that bounds the x- and y-coordinate.
     * @return a point to the left and below the specified point.
     */
    private static Point randomCenter(Point corner)
    {
	int x = corner.getX();
	int y = corner.getY();
        Random generator = new Random();
        return new Point(generator.nextInt(x), generator.nextInt(y));
    }

    /**
     * Returns a radius used in the constructor.
     *
     * @param corner point that bounds the radius.
     * @return a radius used in the constructor.
     */
    private static int randomRadius(Point corner)
    {
        int x = corner.getX();
        int y = corner.getY();
        Random generator = new Random();
        return generator.nextInt(Math.min(x, y) / 2);
    }

    /**
     * Draws this colored circle on the specified component.
     *
     * @param page the component on which this circle is drawn.
     */
    public void draw(Graphics page)
    {
        page.setColor(color);
        int x = center.getX();
        int y = center.getY();        
	page.drawOval(x - radius, y + radius, 2 * radius, 2 * radius);
	page.fillOval(x - radius, y + radius, 2 * radius, 2 * radius);
    }

    /**
     * Returns a string representation of this colored circle.
     *
     * @return a string representation of this colored circle.
     */
    public String toString()
    {
        return "center: " + center.toString() + "\n" +
               "radius: " + radius + "\n" +
	       "color: " + color.toString();
    }
}

