Prev Up Next
Go backward to Adding the Text
Go up to Top
Go forward to Controlling the Text Color

Varying the Text Color

Now, to control the color of the text displayed, you will need to first declare three additional integer variables for the red, blue and green components of the text color just as you declared the three variables for the background color. In "begin" these variables should all be associated with the value "0" since the initial color of the text, black, is represented as 0,0,0.

Next, modify the "drawString" invocation you just placed in "drawDisplay" so that the text is displayed in the color described by the values associated with these three variables. Use the "new Color( ... )" method to produce the desired color. You can test that this has been done correctly by temporarily assigning values other than zeros to the text color variables and running your applet.

Finally, add another "drawString" invocation to "drawDisplay" to include the three numbers that describe the text color to the information displayed.

Note that both lines of text should be drawn in the text color even though the content of one of the lines describes the background color.


Prev Up Next