The Source Image
While you won't see the code for Navigation here, looking at its GIF image and APPLET tag shows clearly what Image Menu is going to do. The source image for Navigation in Figure 30-2 shows seven columns, each of which provides a visual representation of a possible selection. However, each selectable item only has two states, so each row has five redundant copies of the unselected state, The source image.for Image Menu is shown in Given this in ICgC, it ls simple to render Clny of the seven possible states of a six-choice menu. First, draw lmct ) displays the left half of the source image. This is the state where no items arc selected. If any of the items is selected, then the clirfing rectangle is simply set to the bounds-of the selected item, and drawImage( ) is used to display the right-hand side. This will paint just the selected cell through the clipping rectangle,
The APPLET tag for Image Menu has as many pieces of information i.nit as the tag for Navigation, yet it requires fewer than half the lines and is much easier to read. We will use java.util.StringTokenizer to read the urlList and the frame target List parameters whose values a"e plus sign-delimited lists of values. We'll also infer the coordinates of-each menu item by dividing the height of the applet by the number of' URLs parsed in urlList. For readability in the APPLET tag, we also allow a prefix and suffix, which will be concatenated with a URL when it's. time to move to a new page.
This is a small applet exactly 100 lines of Java source. We will walk through all eight methods here and then show all the source together at the end of the chapter .