Suppose that you've been hired to produce a program that draws an image of an archery target that looks like this:

This figure is simply three GOval objects, two red and one white, drawn in the correct order. The outer circle should have a radius of 150 pixels, the white circle has a radius of 100 pixels, and the inner red circle has a radius of 50 pixels. The figure should be centered in the window.

Solution

public class Target extends GraphicsProgram {

	public void run() {
		drawCenteredCircle(150, Color.RED);
		drawCenteredCircle(100, Color.WHITE);
		drawCenteredCircle(50, Color.RED);
	}

	private void drawCenteredCircle(int radius, Color color) {
		GOval oval = new GOval(radius * 2, radius * 2);
		double x = (getWidth() - oval.getWidth()) / 2;
		double y = (getHeight() - oval.getHeight()) / 2;
		oval.setFilled(true);
		oval.setColor(color);
		add(oval, x, y);
	}

}