Prev Up Next
Go backward to Varying the Text Color
Go up to Top
Go forward to Responding to the Choice Menu

Controlling the Text Color

You would like to arrange things so that when the user changes the choice menu selection from "Background" to "Text" the color of the text can be changed using the scrollbars.. As currently written, your "scroll" routine always uses the current settings of the scrollbars to determine the values of the three variables that describe the background color. We could easily change this method to set the variables that control the text colors, but this isn't quite what we need either. Instead, we need to change the method so that the trio of color variables affected is controlled by the current setting of the "Choice" menu included in the applet.

So, add an "if" structure to test to see if the value of the current setting of the Choice menu is equal to "Background". You can get this value by invoking the "getSelectedItem" method of the Choice. If the Choice's value is "Background", the "if" structure you write should choose to execute the three assignments that you originally included in "scroll". If the value is not equal to "Background", it will have to be equal to "Text". In this case, the "if" structure should choose to execute three new assignments very much like the original ones except that they will change the values of the variables that determine the color of the text.

You can test this change by running the applet and then changing both the setting of the Choice menu and the scrollbars. When the "Text" item in the Choice is selected, moving the scrollbars should change the text color. If you pay careful attention, however, you may notice that the transition that occurs when you change the Choice setting isn't quite right yet.


Prev Up Next