Computer Science 121
Assignment 5
Due: November 6, 2001

Create a Java applet that will draw circles or squares of various sizes and colors.  Place them where you wish on the applet.  Run the applet from an html file like the one on the other side of this page.  The red circle defined in the program is only an example.  You may keep it or not as you wish.  But definitely add several more circles or squares with different sizes and colors.  If you decide to draw a square, create a separate SquareFigure class to define and draw it.

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

public class Figures extends Applet
{
     private CircularFigure redCircle;
     // Add declarations for some more circles or squares.
 
     public void init ()
     {
          redCircle = new CircularFigure (Color.red, 100, 30, 20);
          // Get new instances of the circles or squares.
     } // method init
 
     public void paint (Graphics g)
     {
          redCircle.displayCircle (g);
          // Display the additional circles or squares.
     } // method paint
} // class Figures
 
// 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>Figures</TITLE>
     </HEAD>
     <BODY>
          <H1>Figures</H1>
          <APPLET CODE="Figures.class" WIDTH=300 HEIGHT=300></APPLET>
     </BODY>
</HTML>