Prev Up Next
Go backward to Preparation
Go up to Top
Go forward to Drawing the Color Display

Laying Out the Scrollbars

Your first step in this lab should be to add instructions to the body of the "begin" method to create the scrollbars that form the applet's interface. This will include three scrollbars, one for each of the computer's "primary" colors.

When you complete this step the components should all be displayed in the applet. The applet display will look something like:

image
In fact, at the end of this step, the scrollbars you have created will even respond to mouse actions. Manipulating them with the mouse will have little effect, however, until you add event handling methods later in the lab.

The body of the "begin" method you construct at this point should look a bit repetitive. It will contain groups of nearly identical instructions for each of the scrollbars. In each group of instructions, you should create a Slider using "new", then "add" the new component to the applet.

Since you will need to refer to the scrollbars by name in other parts of this applet, you will first need to declare three variables of type "Slider". Pick some appropriate names like "redControl", "greenControl" and "blueControl" or "redslider", "greenslider", and "blueslider" or .... The exact names you choose won't matter but it is best if they sound like names of scrollbars so that you can remember what they are for. The text of these variable declarations should appear before all of your method definitions since these variable names will be shared among several methods.

When you create the Sliders you will associate each "new" Slider with one of these variables in an assignment statement within the "begin" method. Each of these sliders should have a range from 0 to 255 and an initial value of 255 (to reflect the fact that the background will initially be white = 255,255,255).

You can and should test the behavior of your applet by selecting "Run" from the MetroWerks project menu frequently as you go along. For example, it would make sense to make sure that you have the correct instructions to create one scrollbar before typing in the nearly identical code for the other two scrollbars. You can do this by running your applet as soon as you have added the code to include the first Slider. If it works, make sure that you like the way the Slider looks. If necessary, adjust the size of the Slider so that it fits the window well. Then move on to add two modified copies of the instructions that worked for the first Slider. All you should have to modify is the name of the variable each new Slider is associated with


Prev Up Next