mouseDragged( ) Java Help

mouseDragged( )

The mouse Dragged( ) method is called when the mouse moves with any of its.p~tt6ns pressed. In this applet, we want to do the same thIng on drag or move, so we just call mouseMoved( ) directly, passing in the same parameters we received.

mouseMoved( )

Whenever the mouse moves; mouseMoved( ) checks the y coordinate to see which of the cells was selected. If tile selected Cell is different from old Cell, meaning the user moved ham one cell to another, the menu is repainted. This is an optimization that avoids the constant repainting of identical screen bits every time the mouse moves. You will notice repaint( ) is not called here. We are taking a shortcut through the normal applet protocol by calling paint( ) directly after fetching the Graphics context from get Graphics(). This makes for a much snappier response. After the menu is painted, the status line is set to reflect the newly selected item, which is also saved in old Cell.

mouse Released ( )

mouse Released ( )-sends the browser to the URL that corresponds to the currently selected menu item. TI,e desired URL is then constructed. If the URL was improperly formatted in the APPLET tag, the exception is displayed on the status line and returned without attempting to switch documents. The showlfocumentt ) method puts the document described in the URL into the frame listed in the target array. As a final feature, the state of this SHIFT key is checked by calling the isShiftDown( ) method of MouseEvent. If SHIFf was pressed, the URL is opened into a new blank browser window instead of the one specified in target.

Posted on September 18, 2014 in Image Menu: An Image Based Web Menu

Share the Story

About the Author

Back to Top
Share This