Draws a target.
1: /*
2: * File: Target.java
3: * Name:
4: * Section Leader:
5: * -----------------
6: * This file is the starter file for the Target problem.
7: */
8: import acm.graphics.*;
9: import acm.program.*;
10: import java.awt.*;
11: public class Target extends GraphicsProgram {
12: public void run() {
13: drawCircle1(getWidth() / 2 - 72, getHeight() / 2 - 72, 144, 144); //tells the program to render the first circle
14: drawCircle2(getWidth() / 2 - 46.8, getHeight() / 2 - 46.8, 93.6, 93.6); //tells the program to render the second circle
15: drawCircle3(getWidth() / 2 - 21.6, getHeight() / 2 - 21.6, 43.2, 43.2); //tells the program to render the last circle
16: //all these circles pass the 4 required numbers to the methods
17: }
18: public void drawCircle1(double x, double y, double w, double h) { //outer Red
19: GOval circle1 = new GOval(x, y, w, h); //creates the circle with the above dimensions
20: circle1.setColor(Color.RED); //makes it red first
21: circle1.setFilled(true); //fills it (with the red)
22: add(circle1); //draws it
23: }
24: //very similar things for the next two methods.
25: public void drawCircle2(double x, double y, double w, double h) { //middle white
26: GOval circle2 = new GOval(x, y, w, h);
27: circle2.setColor(Color.WHITE);
28: circle2.setFilled(true);
29: add(circle2);
30: }
31: public void drawCircle3(double x, double y, double w, double h) { //inner red
32: GOval circle3 = new GOval(x, y, w, h);
33: circle3.setColor(Color.RED);
34: circle3.setFilled(true);
35: add(circle3);
36: }
37: }