Monday, 24 February 2014

EVENTLISTENER INTERFACES IN JAVA

THE JAVA LISTENER INTERFACES AND THEIR METHODS

Provides interfaces and classes for dealing with different types of events fired by AWT components.

An event listener registers with an event source to receive notifications about the events of a particular type.
Various event listener interfaces defined in the java.awt.event package are given below :



1. The ActionListener interface.


The ActionListener interface is used for handling action events. For example, it's used by a JButton for button clicks, by JCheckbox for checking and unchecking, by a JMenuItem when an option is picked and many other graphical components.

Its general form is shown here:

public interface ActionListener extends EventListener
{
public void actionPerformed(ActionEvent e);

}


2. The AdjustmentListener interface.

This interface defines the adjustmentValueChanged()method that is invoked when an adjustment event occurs.

Its general form is shown here:

void adjustmentValueChanged(AdjustmentEvent ae)

3. The ComponentListener interface.

This interface defines four methods that are invoked when a component is resized,moved, shown, or hidden.

Its general form is shown here:

void componentResized(ComponentEvent ce)
void componentMoved(ComponentEvent ce)
void componentShown(ComponentEvent ce)
void componentHidden(ComponentEvent ce)

4. The ContainerListener interface.


This interface contains two methods. When a component is added to a container,componentAdded( ) is invoked. When a component is removed from a container,componentRemoved( ) is invoked. 

Its general form is shown here:

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

5. The FocusListener Interface


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

Its general form is shown here:

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

6. The ItemListener Interface6. The KeyListener Interface

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

Its general form is shown here:

void itemStateChanged(ItemEvent ie)

7.The KeyListener Interface


This interface defines three methods. The keyPressed( ) and keyReleased( ) methods are invoked when a key is pressed and released, respectively. The keyTyped( ) method is invoked when a character has been entered.

Its general form is shown here:

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

8.The MouseListener Interface


This interface defines five methods. If the mouse is pressed and released at thesame point, mouseClicked( ) is invoked. When the mouse enters a component, themouseEntered( ) method is called. When it leaves, mouseExited( ) is called. ThemousePressed( ) and mouseReleased( ) methods are invoked when the mouse ispressed and released, respectively.


Its general form is shown here:

void mouseClicked(MouseEvent me)
void mouseEntered(MouseEvent me)
void mouseExited(MouseEvent me)
void mousePressed(MouseEvent me)
void mouseReleased(MouseEvent me)

9.The MouseWheelListener Interface

This interface defines the mouseWheelMoved( ) method that is invoked when themouse wheel is moved. 


Its general form is shown here:

void mouseWheelMoved(MouseWheelEvent mwe)

10.The TextListener Interface

This interface defines the textChanged( ) method that is invoked when a change occursin a text area or text field. 

Its general form is shown here:

void textChanged(TextEvent te)

11.The WindowFocusListener Interface

This interface defines two methods: windowGainedFocus( ) and windowLostFocus( ).These are called when a window gains or losses input focus.


Its general form is shown here:

void windowGainedFocus(WindowEvent we)
void windowLostFocus(WindowEvent we)

12.The WindowListener Interface

This interface defines seven methods. ThewindowActivated( ) andwindowDeactivated( )methods are invoked when a window is activated or deactivated, respectively. If awindow is iconified,thewindowIconified( )method is called. When a window is deiconified,thewindowDeiconified( ) method is called. 

Its general form is shown here:

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:

Post a Comment