What are all the listeners in java and explain

Showing Answers 1 - 1 of 1 Answers

Thamizhselvi

  • Jul 23rd, 2007
 

Listeners are created by implementing one or more interfaces defined by the java.awt.event Package.

Commonly used Event Listener Interfaces:

1.ActionListener : This interface defines the actionPerformed(). It is invoked when  an action event occurs.

void actionPerformed(ActionEvent ae)

2. AdjustmentListener: This interface defines the adjustmentValueChanged().It is invoked when an adjustment event occurs.

void adjustmentValueChanged(AdjustmentEvent ae)

3.ComponentListener:

This interface defines 4 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)

componentResized(),componentMoved() methods are provided for notification purpose only.

4.ContainerListener:

This interface contains 2 methods,

1. componentAdded() : When a component is added to a container, it is invoked.
2.componentRemoved(): When a component is removed  from a container, it is invoked.

void componentAdded(ContainerEvent ce)
void componentRemoved(ContainerEvent ce)

5.FocusListener:

This interface has two methods.When a component obtains keyboard focus, focusGained() is invoked. When a component loses keyboard focus, focusLost() is invoked.

void focusGained(FocusEvent fe)
void focusLost(FocusEvent fe)

6.ItemListener:

This interface defines itemStateChanged().It is invoked
when the state of an item changes.

void itemStateChanged(ItemEvent ie)

7.KeyListener:

This interface has 3 methods.
The keyPressed() and keyReleased() are invoked when a key is pressed and released.
The keyTyped() is invoked when a character has been entered.

void keyPressed(KeyEvent ke)
void keyReleased(KeyEvent ke)
void keyTyped(KeyEvent ke)

8.MouseListener:

This interface defined 5 methods.

1.If the mouse is pressed & released at the same point mouseClicked() is invoked.

void mouseClicked(MouseEvent me)

2.When the mouse enters a component the mouseEntered() is called.

void mouseEntereded(MouseEvent me)

3.When it leaves,mouseExited() is called.

void mouseExited(MouseEvent me)

4.&5. The mousePressed() & mouseReleased() are invoked when the mouse is pressed & released.

void mousePressed(MouseEvent me)
void mouseReleased(MouseEvent me)

9.MouseMotionListener:

This interface has 2 methods. The mouseDragged() & mouseMoved() methods are invoked when the mouse is dragged & moved multiple times.

void mouseDragged(MouseEvent me)
void mouseMoved(MouseEvent me
)

10.TextListener:

This interface defines textChanged(),it is invoked when a change occur in text area or text field.

void tetChanged(TextEvent te)

11.WindowListener:

This interface defined 7 methods.

*** The windowActivated() & windowDeactivated() are invoked when a window is activated or deactivated respectively.

void windowActivated(WindowEvent we)
void windowDeactivated(WindowEvent we)

*** A window is opened or closed then windowOpened() or windowClosed() are called respectively.

void windowOpened(WindowEvent we)
void windowClosed(WindowEvent we)

*** If a window is iconified & deiconified then windowIconified() & windowDeiconified() are called respectively.

void windowIconified(WindowEvent we)
void windowDeiconified(WindowEvent we)

*** The windowClosing() is invoked when a window being closed.

void windowClosing(WindowEvent we)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions