Computer Science II, Lab 08

Tuesday, October 9th

Letting Users Choose the Color of the CannonBall


Introduction


Tasks

  1. Start by downloading the starter code for this lab.  Look at the code so you can see how this is different from the code distributed earlier.  The main changes are

     

  2. Your first real task is to make it so that the ColorWheel class has real functionality.

    Recall that last semester you worked with Pixels, each of which knew their Color.  The Color class includes a three-argument constructor that lets the creator of the Color object define a color based on saturation values of red, green, and blue pigment, respectively. Each argument must be an int between 0 and 255, inclusive.

    A ColorWheel is a window with a large, stationary Ball in its center. It has sliders for the red saturation value (left), the green saturation value (top), and the blue saturation value (right). It also has textual "labels" to help the user keep them straight.  Each label contains the color represented by the slider and the color's current value. 

    When the user moves a slider, the saturation value for the associated color changes, the ball changes color in the window, and the color's label displays the value of the slider.

    A ColorWheel responds to the public message getColor() by returning its current color as a Color. A ColorWheel also uses this method to compute the new color of the ball in its paint() method.

    [Note: While I use the term "Label" above, you are not actually required to use the JLabel class.  You may use drawString like Budd does in CannonWorld.  Of course, if you prefer, you may use JLabel - probably placed with a scrollbar inside of a JPanel and then using BorderLayout to place the Panel.  drawString() is probably easier, but not as pretty.  JPanel is probably more complicated, but gives you cleaner results (perhaps).]

     

    Test this class using a simple demo application class before proceeding to the next task.

     

  3. Modify the CannonWorldDriver class to create a ColorWheel and send it to the CannonWorld as a parameter.  If you get things set up correctly you should be able to control the color of the ball at all times.
  4.  

  5. Go back through your ColorWheel class and double check whether you actually NEED all of the instance variables you have declared.  My guess is that many of you have created 7-10 instance variables in the ColorWheel class while only a handful (3 or 4?) are actually necessary..

 

NOTE:

When a Java application displays more than one window, some systems show the windows in the same location on the screen. You can handle this situation in at least two ways:

I prefer that you use the second approach.


Deliverables

Using the homework submission system, upload:

Be sure that your submission follows all homework submission requirements.