CS 105 Lab 7 -- Fall 1998

This week we will return to working with Java in lab. You will develop a somewhat more sophisticated version of the color mixer applet you created in lab 4.

This week's lab is intended to give you some experience using three new aspects of Java. The most obvious new feature will be a new user interface component, the "Choice." This component allows you to easily add pop-up menus to an applet. The result will be that the final product of this lab will look surprisingly like a useful, functional piece of computer software.

The less obvious but more important new features you will encounter in this lab are the conditional statement or "if statement" and the use of variables to remember aspects of the "state" of your applet.

The applet you construct will again allow its user to vary colors by adjusting redness, greenness and blueness using scrollbars. This time, however, the user will be able vary both the background and text colors used in the applet's screen region so that the user can "design" a pair of foreground and background colors that works well. A working version of the completed applet is included below so that you can understand its functionality.


The applet displays three scrollbars. Initially, changing the positions of the scroll boxes control the color of the background displayed in the area below the scrollbars. Each scrollbar can be used to increase or decrease the amount of one color included in the mix that produces the color displayed.

In addition, the applet displays a choice menu that can be used to select either "Text" or "Background" as the target of the scrollbars. If you select "Text" instead of "Background", changing the scrollbars with the mouse will change the text color rather than the background color.

The text displayed provides the color numbers that would be needed to produce the colors viewed using the Java "new Color(...)" constructor method.

The instructions in the remainder of this handout are intended to guide you rather carefully through the construction of this applet. My goal will be to explain what methods are needed and what each method should do in English. Your job will be to translate my English descriptions of the methods into Java. Many of the Java details you will need to complete this task are not included in this document. Instead, they can be found in the "Java Programming with JavaTools" document. (The following link will take you to this JavaTools documentation .). You should bring the copies of this document I distributed for lab 3 with you when you come to lab this week.


To simplify printing, a version of the complete instructions for this lab as a single page is also available. Otherwise, follow the links below to read the remainder of this lab description.

If you have questions about the instructions for this lab, you are encouraged to ask them through the discussion area for this lab in the course discussion forum.


  • Preparation
  • Adding the "Choice" menu
  • Handling the Scrollbars
  • Adding the Text
  • Varying the Text Color
  • Controlling the Text Color
  • Responding to the Choice Menu
  • Finishing Up