The United States Flag
Here is the order we will do things in:
- First, referring to the file CarApplet.java, finish the code in the file FlagApplet.java.
- Second, code the method signatures of the paintWhiteBackground(), paintRedStripes(), and paintBlueField() methods in that order by following the instructions in the file.
- Third, make sure you add the beginning and ending curly braces for each method.
- Fourth, call the above three methods inside the paintComponent() method, even though you haven't written the code for the methods. Also call super.paintComponent(g); where you are suppose to according to the instructions in this method.
- Fifth, study the Flag Layout web page before continuing and then ...
- Sixth, write the code inside the paintWhiteBackground() method and then run the program to see that the white background is painted.
- Seventh, write the code inside the paintRedStripes() method and then run the program to see that the red strips are painted.
- Eighth, write the code inside the paintBlueField() method and then run the program to see that the blue field is painted.
- Now complete the remainder of the methods by following this order:
- Study the layout of a star using the Star Layout diagram.
- Write the code for the paintStar() method so that it paints one star in the upper left hand corner of the blue field.
- Discuss how to modify the paintStar() method so that a star can be painted anywhere in a graphics window.
- Modify the paintStar() method and then modify your call for this method in paintComponent so a star is painted at (100, 100). We're just trying to test the method.
- Now, write the paintStars() method. Follow these instructions:
- Paint your first star in the first row of stars at the coordinates (20, 20) by calling the paintStar() method.
- Figure out where to print your second star in the first row of stars. Note: All stars in a row are 40 pixels from each other horizontally.
- Paint your first star in the second row of stars at the coordinates (40, 40) by calling the paintStar() method. Note: All stars in a column are 20 pixels from each other vertically.
- Note that a star in any row is offset horizontally from the stars in the rows immediately above and below.
- Finally, comment out your two calls to the paintStar() method in the paintComponent() method and call the paintStars() method instead. Now run the program to see your completed Flag.
Back to Top