O'Reilly logo

Graphic Java™ 1.2, Volume I: AWT, Third Edition by David M. Geary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mouse Button Events

To illustrate handling mouse button events, we'll describe a MouseSensorApplet. The MouseSensorApplet uses a BorderLayout layout manager and places an instance of a MouseSensorCanvas in the center of the applet. Remember that an applet is an extension of Container, so components can be added to an applet. (Since most of the applets in this chapter simply place a blank canvas inside an applet, we won't show pictures of them unless there's something to illustrate.) The MouseSensorCanvas class overrides the mouseDown(), mouseUp(), and mouseDrag() convenience methods from java.awt.Component. It also implements a whichMouseButton method to print the mouse button that initiated the event. Example 8-1 shows the implementation for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required