Tracking Mouse Events on a JPanel
The MouseTracker
application (Figs. 12.28–12.29) demonstrates the MouseListener
and MouseMotionListener
interface methods. The event-handler class (lines 36–97 of Fig. 12.28) implements both interfaces. You must declare all seven methods from these two interfaces when your class implements them both. Each mouse event in this example displays a String
in the JLabel
called statusBar
that is attached to the bottom of the window.
Get Java™ How To Program (Early Objects), Tenth 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.