Java Reference
In-Depth Information
LISTING 8.20
continued
private class
LineListener
implements
MouseListener,
MouseMotionListener
{
//--------------------------------------------------------------
// Captures the initial position at which the mouse button is
// pressed.
//--------------------------------------------------------------
public void
mousePressed (MouseEvent event)
{
point1 = event.getPoint();
}
//--------------------------------------------------------------
// Gets the current position of the mouse as it is dragged and
// redraws the line to create the rubberband effect.
//--------------------------------------------------------------
public void
mouseDragged (MouseEvent event)
{
point2 = event.getPoint();
repaint();
}
//--------------------------------------------------------------
// Provide empty definitions for unused event methods.
//--------------------------------------------------------------
public void
mouseClicked (MouseEvent event) {}
public void
mouseReleased (MouseEvent event) {}
public void
mouseEntered (MouseEvent event) {}
public void
mouseExited (MouseEvent event) {}
public void
mouseMoved (MouseEvent event) {}
}
}
SELF-REVIEW QUESTIONS
(see answers in Appendix N)
SR 8.28
What is a mouse event?
SR 8.29
What sequence of mouse events is generated when the mouse button is
clicked over a GUI component and then released?
SR 8.30
What sequence of mouse events is generated when the mouse button is
clicked over a GUI component, the mouse is moved so it is no longer
over that component, and then the mouse button is released?
Search WWH ::
Custom Search