Listeners
are created by using one or more of the interfaces defined by the java.awt.event package.
When
an event occurs, the event source invokes the appropriate method defined by the
listener and provides an event object as its argument.
The
commonly used listener interfaces are:
The ActionListener
Interface:
The
ActionListener interface defines actionPerformed()
method that is invoked when an action event occurs.
void
actionPerformed(ActionEvent ae)
The AdjustmentListener
Interface:
This
interface defines the adjustmentValueChanged()
method that is invoked when an adjustment event occurs.
void adjustmentValueChanged(AdjustmentEvent
ae)
The
ComponentListener Interface:
This
interface defines four methods that are invoked when a component is resized,
moved, shown or hidden.
void componentResized(ComponentEvent
ce)
void componentMoved(ComponentEvent
ce)
void componentShown(ComponentEvent
ce)
void componentHidden(ComponentEvent
ce)
The
ContainerListener Interface:
This
interface defines two methods that are invoked when a component is added to or
removed from a container.
void componentAdded(ContainerEvent
ce)
void componentRemoved(ContainerEvent
ce)
The
FocusListener Interface:
This
interface defines two methods that are invoked when a component ontains or
loses keyboard focus.
void
focusGained(FocusEvent fe)
void focusLost(FocusEvent
fe)
The
ItemListener Interface:
This
interface defines the itemStateChanged()
methods that is invoked when the state of an item changes.
void
itemStateChanged(ItemEvent ie)
The
KeyListener Interface:
This
interface defines three methods that are invoked when a key is pressed,
released or when a character has been entered.
void keyPressed(KeyEvent
ke)
void KeyReleased(KeyEvent
ke)
void KeyTyped(KeyEvent
ke)
The
MouseListener Interface:
This
interface defines five methods. If the mouse is pressed or released at the same
point, mouseClicked() is invoked. When
the mouse enters a component, the mouseEntered()
event is called. When it leaves mouseExited()
method is called. The mousePressed()
and mouseReleased() methods are
invoked when the mouse is pressed or released, respectively.
void mouseClicked(MouseEvent
me)
void
mouseEntered(MouseEvent me)
void
mouseExited(MouseEvent me)
void
mousePressed(MouseEvent me)
void
mouseReleased(MouseEvent me)
The
MouseMotionListener Interface:
This
interface defines two methods. The mouseDragged()
method is called multiple times as the mouse is dragged. The mouseMoved() method is called multiple
times as the mouse is moved.
void
mouseDragged(MouseEvent me)
void mouseMoved(MouseEvent
me)
The
MouseWheelListener Interface:
This
interface defines mouseWheelMoved()
method that is called when the mouse wheel is moved.
void
mouseWheelMoved(MouseWheelEvent mwe)
The
TextListener Interface:
This
interface defines textChanged()
method that is called when a change occurs in a text area or text field.
void textChanged(TextEvent
te)
The
WindowFocusListener Interface:
This
interface defines two methods that are called when a window gains or loses
input focus.
void
windowGainedFocus(WindowEvent we)
void
windowLostFocus(WindowEvent we)
The
WindowListener Interface:
This
interface defines seven methods. The windowActivated()
and windowDeactivated() methods are
invoked when a window is activated or deactivated, respectively. If a window is
iconified, the windowIconified()
method is called. When a window is deiconified, the windowDeiconified() method is called. When a window is opened or
closed, the windowOpened() or windowClosed() method is called. When
the window is being closed the windowClosing()
method is called.
void windowActivated(WindowEvent
we)
void windowClosed(WindowEvent
we)
void
windowClosing(WindowEvent we)
void
windowDeactivated(WindowEvent we)
void windowDeiconified(WindowEvent
we)
void
windowIconified(WindowEvent we)
void
windowOpened(WindowEvent we)
No comments:
Write comments