RingShadow - } /* * Adds a ring to the canvas at position...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * File: RingShadow.java * --------------------- * This program draws a ring and its shadow. This * version of the program draws several circles to make the rings * wider. Some coordinate values are explicit. * * As of Chapter 2, you don't yet have methods or the loop * statements and would therefore have to write this program * using a single unsubdivided run method; * this code shows the program as you will eventually write it. * * Author: CS1MD3 */ import acm.graphics.*; import acm.program.*; import java.awt.*; i public class RingShadow extends GraphicsProgram { p public void run() { /* draw the shadow */ addRing(250, 180, Color.GRAY); /* draw the ring above the shadow */ addRing(250, 150, Color.YELLOW);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } /* * Adds a ring to the canvas at position (*x*, *y*) and of color * *color*. The radius of the ring is RING_RADIUS and the thickness * is THICKNESS pixels. */ private void addRing(int x, int y, Color color) { int height = RING_RADIUS / 2; /* draw ring THICKNESS times to make the ring wider */ for (int i = 0; i < THICKNESS; i++) { GOval ring = new GOval(x + i, y + i, 2 * (RING_RADIUS - i), 2 * (height - i)); ring.setColor(color); ring.setFilled(false); add(ring); } /* for i */ } /* addRing */ /* Private constants */ private static final int RING_RADIUS = 100; private static final int THICKNESS = 10; }...
View Full Document

This note was uploaded on 10/27/2009 for the course COMP SCI 1MD3 taught by Professor Various during the Winter '07 term at McMaster University.

Ask a homework question - tutors are online