Computer Science 121
Assignment 3
Due: February 20, 2001

Create a Java applet that will draw circles of various sizes and colors. Place them where you wish on the applet. Run the applet from an html file like the one below. The red circle defined in the file is only an example. You may keep it or not as you wish. But definitely add several more circles with different sizes and colors.

import java.awt.*;
import java.applet.Applet;

public class Circles extends Applet
{
    private CircularFigure redCircle;
    // Add declarations for some more circles.

    public void init ()
    {
        redCircle = new CircularFigure (Color.red, 100, 30, 20);
        // Get new instances of the circles.
    } // method init

    public void paint (Graphics g)
    {
        redCircle.displayCircle (g);
        // Display the additional circles.
    } // method paint
} // class Circles

// A class that can display a circle.
class CircularFigure
{
    private Color circleColor;
    private int x, y, diameter;

    CircularFigure (Color color, int xValue, int yValue, int d)
    {
        circleColor = color;
        x = xValue;
        y = yValue;
        diameter = d;
    } // constructor

    public void displayCircle (Graphics g)
    {
        g.setColor (circleColor);
        g.fillOval (x, y, diameter, diameter);
    } // method displayCircle
} // class CircularFigure

<HTML>
    <HEAD>
        <TITLE>Circles</TITLE>
    </HEAD>
    <BODY>
        <H1>Circles</H1>
        <APPLET CODE="Circles.class" WIDTH=300 HEIGHT=300></APPLET>
    </BODY>
</HTML>