DrawADoughnut


Your browser is ignoring the <APPLET> tag!

This program draws a doughnut when the program starts.

import objectdraw.*;
import java.awt.*;

/**
 * Draw a simple doughnut
 * 
 * @author Barbara Lerner
 * @version March 5, 2008
 */
public class DrawADoughnut extends WindowController
{
    /**
     * Draw a doughunt
     */
    public void begin()
    {
        new Doughnut (canvas);
    }
}

import java.awt.*;
import objectdraw.*;

/**
 * Draws a doughnut as 2 concentric circles
 * 
 * @author Barbara Lerner 
 * @version March 5, 2008
 */
public class Doughnut
{
    // Location and size of outer circle
    private static final int OUTER_LEFT = 100;
    private static final int OUTER_TOP = 100;
    private static final int OUTER_SIZE = 100;

    // Location and size of inner circle.  The inner circle has half the
    // diameter of the outer circle.  Their centers are the same.
    private static final int INNER_SIZE = OUTER_SIZE / 2 ;
    private static final int INNER_LEFT = OUTER_LEFT + (OUTER_SIZE / 2) - (INNER_SIZE / 2);
    private static final int INNER_TOP = OUTER_TOP + (OUTER_SIZE / 2) - (INNER_SIZE / 2);

    /**
     * Draw the 2 circles that make up the doughnut.
     */
    public Doughnut (DrawingCanvas doughnutCanvas) {
        new FramedOval (OUTER_LEFT, OUTER_TOP, OUTER_SIZE, OUTER_SIZE, doughnutCanvas);
        new FramedOval (INNER_LEFT, INNER_TOP, INNER_SIZE, INNER_SIZE, doughnutCanvas);
    }
}