-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullseye.java
More file actions
43 lines (34 loc) · 1.16 KB
/
Bullseye.java
File metadata and controls
43 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//********************************************************************
// Bullseye.java Author: Lewis/Loftus/Cocking
//
// Demonstrates the use of conditionals and loops to guide drawing.
//********************************************************************
import java.applet.Applet;
import java.awt.*;
public class Bullseye extends Applet
{
//-----------------------------------------------------------------
// Paints a bullseye target.
//-----------------------------------------------------------------
public void paint (Graphics page)
{
int x = 0, y = 0, diameter;
setBackground (Color.cyan);
diameter = 300;
page.setColor (Color.white);
for (int count = 0; count < 5; count++)
{
if (page.getColor() == Color.black) // alternate colors
page.setColor (Color.white);
else
page.setColor (Color.black);
page.fillOval (x, y, diameter, diameter);
diameter -= (2 * 25);
x += 25;
y += 25;
}
// Draw the red bullseye in the center
page.setColor (Color.red);
page.fillOval (x, y, diameter, diameter);
}
}