Generally you respond to mouse events directed at your component,
by registering a MouseListener
object with the
component.
public interface MouseListener extends
EventListener
For reasons of efficiency, the MouseListener
interface only declares five methods:
public abstract void mouseClicked(MouseEvent evt)
public abstract void mousePressed(MouseEvent evt)
public abstract void mouseReleased(MouseEvent evt)
public abstract void mouseEntered(MouseEvent evt)
public abstract void mouseExited(MouseEvent evt)
A mouse listener does not respond to mouse dragged or mouse moved
events because these are too common. Responding to each of them,
even with a noop method, would result in many unnecessary method
calls. Instead, mouse moved and mouse dragged events are responded
to by the MouseMotionListener
interface.
public interface MouseMotionListener extends
EventListener
The MouseMotionListener
interface declares these
two methods that are missing from MouseListener
:
public abstract void mouseDragged(MouseEvent evt)
public abstract void mouseMoved(MouseEvent evt)
If you don't care about mouse dragged and mouse moved events, then
you simply don't register a MouseMotionListener
on the component;
and the component won't bother to report such events.