Prev Up Next
Go backward to Drawing the Background
Go up to Drawing the Color Display
Go forward to Adding the Text

Adding the Color Value Rectangles

Now that it is somewhat hooked into your applet, we can proceed to complete the method that draws the background. The missing pieces are the instructions that draw the red, green and blue rectangles and the color numbers that appear within them.

For this next step, don't worry about the numbers, just get the three colored rectangles drawn. This should be done by adding three invocations of "fillRect" to the end of your background drawing applet. The first of the "fillRect" invocations should use the color "Red", the second "Green" and the last "Blue". The trick part is that in these "fillRect" invocations you can not leave out the four parameters that specify the location and size of the rectangles. The applet screen region is 200 pixels wide. So, each of your rectangles should be 66 pixels high and about 66 pixels wide. Remember that the y axis is upside down, so the y coordinate of each rectangle will be about 134 (= 200 - 66). With this much information, you should be able to add the needed parameters to the "fillRect" invocations.

Again, to avoid wasting time typing incorrect Java code, you should probably first just add the "fillRect" invocation you think will draw the "Red" rectangle. Then, "Run" the applet until it works as it should. Then, make two copies of the original "fillRect", modify the colors and coordinates as needed and run it again until it works.


Prev Up Next