Java Reference
In-Depth Information
mouse is moved or dragged with a button pressed.
TABLE 18-9
:
MouseMotionListener Methods
METHOD
DESCRIPTION
Called when the mouse is moved when the cursor is on a component.
mouseMoved(MouseEvent
e)
Called when the mouse is moved when the cursor is on a component while a mouse but-
ton is held down.
mouseDragged(MouseEvent
e)
The MouseWheelListener Interface
wheel being rotated. This is frequently used to scroll information that is displayed, but you can use it in any
way that you want.
TABLE 18-10
:
MouseWheelListener Method
METHOD DESCRIPTION
mouseWheelMoved(MouseWheelEvent e)
Called when the mouse wheel is rotated.
The KeyListener Interface
The
KeyListener
interface declares methods (shown in
Table 18-11
) to respond to events arising when a
key on the keyboard is pressed or released.
TABLE 18-11
:
KeyListener Methods
METHOD DESCRIPTION
keyTyped(KeyEvent e)
Called when a key is pressed and then released.
keyPressed(KeyEvent e)
Called when a key is pressed.
keyReleased(KeyEvent e)
Called when a key is released.
The FocusListener Interface
The
FocusListener
interface declares methods (shown in
Table 18-12
) to respond to a component gaining
or losing the focus. You might implement these methods to change the appearance of the component to re-
flect whether or not it has the focus.
TABLE 18-12
:
FocusListener Methods
METHOD DESCRIPTION
focusGained(FocusEvent e)
Called when a component gains the focus.
focusLost(FocusEvent e)
Called when a component loses the focus.
There is a further listener interface,
MouseInputListener
, that is defined in the
javax.swing.event
package. This listener implements both the
MouseListener
and
MouseMotionListener
interfaces so it de-
clares methods for all possible mouse events in a single interface.
The
WindowListener
,
WindowFocusListener
, and
WindowStateListener
interfaces declare methods
corresponding to each of the event IDs defined in the
WindowEvent
class that you saw earlier. If you deduced