paint( )

The paint () method is quite simple. First, it checks to seen the offscreen buffer has been created. yet. If it hasn’t, lateInit( ) is called to create the buffer and load the menu image. After that, it draws the left half of the image on the offscreen buffer. This requires, of course, that the menu image be twice the width of the applet. That way, the applet will simply clip awar. the right half of the menu image when drawImage(img, 0, 0, null) is called. Then, if any cell is selected (selected Cell >= 0), it sets the clip rectangle to the bounds of that menu item. You’ll notice that paint() gets the graphics context of the offscreen image every time. This has the effect of resetting the clipping rectangle to the bounds of the image. AWT’s lack of a resetClip() method requires some strange coding style.

Next, the entire image is painted again, but this time, it is offset by the width of the applet to the left, via drawimage img, -d.width, 0, null). This has the effect of placing just the right highlighted menu hem in the clip rectangle. Lastly, tile offscreen buffer is .copied to the applet window.

Mouseexited ()

Special is needed for mouseexited( ), because it causes all of the menu items to be unselected. All we have to do it; set selected Cell and old Cell to 1, which makes the subsequent paint( ) call show aU the’ Hems as unselected. Having old Cell set to -1 ‘ means that the next time the mouse enters tile applet and causes a mouseMoved() call, the Ilrst item will paint properly.

[vfb id=1]

Share This