CS 140 - Lab 6, Thursday Sep 18

Objectives

  1. More practice with for-loops

The Lab

Create a new Java class named Lab6 and save it on your P: drive in a file named Lab6.java. Add a main method and make sure it compiles before you proceed.

To see how your lab will finally look run my version by double clicking on My Computer and going to the folder T:/Harcourt/Fall2008/CS140/Lab6 and then double click on the file run.bat. Here's a picture:

  1. Add to your Lab6 class the Java code to create and show 256 X 256 blank canvas.
  2. Think of the canvas as being divided into four quadrants. Starting with the upper left quadrant fill it in by repeatedly drawing a vertical line from the left. Get this working for black lines to start. After that's working change the color of each line based on the for-loop variable. Don't forget how to make a new color.
      g.setColor(new Color(red,green,blue));
    
    makes a new color based on the values in the integer variables red, green, and blue assuming they have been declared properly and given values.
  3. Fill in the upper right quadrant by drawing horizontal lines from the top. Shade your lines.
  4. Fill in the lower left quadrant by drawing two lines simultaneously from the upper left corner and the lower right corner of the quadrant.
  5. Fill in the lower right quadrant using vertical lines coming in from the left and right simultaneously.