Picture Lab Activity 2

<< Picture Lab Activity 1 | Picture Lab | Picture Lab Activity 3 >>

Picking a Color

Run the main method in ColorChooser.java. This will pop up a window (Figure 2) asking you to pick a color. Click on the RGB tab and move the sliders to make different colors.

When you click the OK button, the red, green, and blue values for the color you picked will be displayed as shown below. The Color class has a toString method that displays the class name followed by the red, green, and blue values. The toString method is automatically called when you print an object.


Java represents color using the java.awt.Color class. This is the full name for the Color class, which includes the package name of java.awt followed by a period and then the class name Color. Java groups related classes into packages. The awt stands for Abstract Windowing Toolkit, which is the package that contains the original Graphical User Interface (GUI) classes developed for Java. You can use just the short name for a class, like Color, as long as you include an import statement at the beginning of a class source file, as shown below. The Picture class contains the following import statement.

import java.awt.Color;

Use the ColorChooser class (run the main method) to answer the following questions.


  1. How can you make pink?
  2. How can you make yellow?
  3. How can you make purple?
  4. How can you make white?
  5. How can you make dark gray?