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 ...

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.