H:\CSC120\Java\lec03\src\Flag.java
 1 import java.awt.*;
 2 /**
 3     A graphical class that displays as a flag.
 4 
 5     The flag is a rectangle of one color with a
 6     vertical stripe of another color.
 7     Author Louise Moses. Modified by John Kirchmeyer
 8     Version 1.0 June 9, 2004
 9 */
10 public class Flag {
11 
12     // The background color of this flag object.
13     private Color flagColor;
14 
15     // The color of the vertical stripe.
16     private Color stripeColor;
17 
18     // The horizontal position of the upper left corner of this Flag object.
19     private Integer over;
20 
21     // The vertical position of the upper left corner of this Flag object.
22     private Integer down;
23 
24     // The overall width of this Flag object.
25     private final Integer WIDTH  = 200;
26 
27     // The overall height of this Flag object.
28     private final Integer HEIGHT = 120;
29 
30     /**
31      * Create and Initialize a new Flag.
32      *   ov        The horizontal position of the upper left corner of this Flag object.
33      *   dn        The vertical position of the upper left corner of this Flag object.
34      *   flagCol   The background color of this Flag object.
35      *   stripeCol The color of the horizontal stripe.
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     } // end of constructor
43 
44     /**
45      * Draws this Flag object on the Graphics context g.
46      *   g       A Graphics context on which to draw.
47     */
48     public void draw(Graphics g) {
49         g.setColor(flagColor);
50         g.fillRect(over, down, WIDTH, HEIGHT);
51 
52         //vertical bar in the middle
53         g.setColor(stripeColor);
54         g.fillRect(over+(WIDTH/3), down, (WIDTH/3), HEIGHT);
55 
56        
57         //outline the flag in black
58         g.setColor(Color.BLACK);
59         g.drawRect(over, down, WIDTH, HEIGHT);
60         
61     } // end of draw
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     } // end of toString
75 
76 }// end of class Flag
77