H:\CSC120\Java\lec03\src\Flag.java |
1 import java.awt.*;
2
3 A graphical class that displays as a flag.
4
5
6
7
8
9
10 public class Flag {
11
12
13 private Color flagColor;
14
15
16 private Color stripeColor;
17
18
19 private Integer over;
20
21
22 private Integer down;
23
24
25 private final Integer WIDTH = 200;
26
27
28 private final Integer HEIGHT = 120;
29
30
31 Create and Initialize a new Flag.
32
33
34
35
36
37 public Flag(Integer ov, Integer dn, Color flagCol, Color stripeCol) {
38 over = ov;
39 down = dn;
40 flagColor = flagCol;
41 stripeColor = stripeCol;
42 }
43
44
45 Draws this Flag object on the Graphics context g.
46
47
48 public void draw(Graphics g) {
49 g.setColor(flagColor);
50 g.fillRect(over, down, WIDTH, HEIGHT);
51
52
53 g.setColor(stripeColor);
54 g.fillRect(over+(WIDTH/3), down, (WIDTH/3), HEIGHT);
55
56
57
58 g.setColor(Color.BLACK);
59 g.drawRect(over, down, WIDTH, HEIGHT);
60
61 }
62
63
64 Returns a string representation of the values of this Flag object's over, down, flagColor, and stripeColor fields.
65
66 public String toString() {
67 String tempString;
68
69 tempString = "Flag with over=" + over
70 + " down=" + down
71 + " flagColor=" + flagColor.toString()
72 + " stripeColor=" + stripeColor.toString();
73 return tempString;
74 }
75
76 }
77