Java Reference
In-Depth Information
(continued)
listener (interface): method
to add
can Be used With: purpose
method(s) to implement
Focus Listener
(FocusListener) -
addFocusListener
Fires FocusEvent when compo-
nent loses or gains focus.
All components accept this listener.
focusGained and focusLost :
Code that reacts when compo-
nent gains or loses focus.
Key Listener
(KeyListener) -
addKeyListener
Fires KeyEvent when user types
on the keyboard and the com-
ponent the listener is registered
with has focus.
All components accept this
listener.
keyTyped : Code that reacts when
user types a key (presses and
releases a key).
keyPressed and keyReleased :
Code that reacts when user
presses and releases a key.
Mouse Listener
(MouseListener)
- addMouseListener
Fires MouseEvent when the
mouse pointer interacts with a
component.
All components accept this
listener.
mouseClicked : Code that reacts
when a user clicks a mouse button.
mouseEntered and mouseExited :
Code that reacts when the
mouse pointer enters or exits a
component.
mousePressed and
mouseReleased : Code that reacts
when user presses and releases a
mouse button.
Mouse Motion Listener
(MouseMotionListener)
- addMouseMotionListener
Fires MouseEvent when the
mouse pointer is dragged or
moved over a component.
All components accept this
listener.
mouseDragged : Code that reacts
when a user moves the mouse
while holding a mouse button
down.
mouseMoved : Code that reacts
when a user moves the mouse.
Mouse Wheel Listener
(MouseWheelListener)
- addMouseWheelListener
Fires MouseWheelEvent when
user scrolls the mouse wheel.
All components accept this
listener.
mouseWheelMoved : Code that
reacts when the user moves the
mouse wheel.
Mouse Adapter
(MouseAdapter) -
addMouseListener,
addMouseMotionListener,
addMouseWheelListener
Can be used to define all three
mouse event listeners at the
same time. Convenience class.
See three mouse event listeners
above.
Don't worry if the amount of event types and listeners seems overwhelming for now (and this isn't
even all of them). Just refer to this table when you encounter a need to add more behavior to your
components. In most cases, using action listener should cover most of your needs.
Search WWH ::




Custom Search