Popular Listener Interfaces In Java

0
35
Spread the love
  • 28
  • 34
  • 28
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    137
    Shares

Popular Listener Interfaces In Java

WindowListener Interface in java

WindowListener interface defines the methods that an object must implement to “listen” for window events on AWT components. When a WindowEvent occurs, an AWT component notifies its registered WindowListener objects by invoking one of their methods.
A simple way to implement this interface is by subclassing the WindowAdapter class.

The structure of the WindowListener interface is given as

public abstract interface  java.awt.event.WindowListener extends java.util.EventListener {
// Public Instance Methods
abstract void windowActivated(WindowEvent e);
public abstract void windowClosed(WindowEvent e);
public abstract void windowClosing(WindowEvent e);
public abstract void windowDeactivated(WindowEvent e);
public abstract void windowDeiconified(WindowEvent e);
public abstract void windowIconified(WindowEvent e);
public abstract void windowOpened(WindowEvent e);
}

TextListener Interface in java

TextListener interface defines the method that an object must implement to “listen” for text events on AWT components. When a TextEvent occurs, an AWT component notifies its registered TextListener objects by invoking their textValueChanged() methods.

public abstract interface java.awt.event.TextListener extends java.util.EventListener{
// Public Instance Methods
public abstract void textValueChanged(TextEvent e);
}

TextListener Interface in java

TextListener interface defines the methods that an object must implement to ” listen ” for mouse motion events on AWT components. When a MouseEvent occurs involving a mouse drag or mouse motion with no buttons down, an AWT component notifies its registered MouseMotionListener objects by invoking one of their methods.

An easy way to implement this is by subclassing the MouseMotionAdapter class.

public abstract interface java.awt.event.MouseMotionListener extends java.util.EventListener{
// Public Instance Methods
public abstract void mouseDragged (MouseEvent e);
public abstract void mouseMoved (MouseEvent e);
}

MouseListener Interface in java

MouseListenerinterface defines the methods that an object must implement to “listen” for mouse events on AWT components. When a MouseEvent occurs, an AWT component notifies its registered MouseListener objects (or MouseMotionListener objects if the event involves mouse motion) by invoking one of their methods.

An easy way to implement this interface is by subclassing the MouseAdapter class.

public abstract interface java.awt.event.MouseListener extends java.util.EventListener{
// Public Instance Methods
public abstract void mouseClicked (MouseEvent e);
public abstract void mouseEntered (MouseEvent e);
public abstract void mouseExited (MouseEvent e);
public abstract void mouse Pressed (MouseEvent e);
public abstract void mouseReleased (MouseEvent e);
}

ItemListener Interface in java

ItemListener interface defines the method that an object must implement to “listen” for item events on AWT components. When an ItemEvent occurs, an AWT component notifies its registered ItemListener objects by invoking their itemStateChanged() methods.

public abstract interface java.awt.event.ItemListener extends java.util.EventListener{
// Public Instance Methods
public abstract void itemStateChanged (ItemEvent e);
}

KeyListener Interface in java

KeyListener interface defines the methods that an object must implement to “listen” for key events on AWT components. When a KeyEvent occurs, an AWT component notifies its registered KeyListener objects by invoking one of their methods.
An easy way to implement this interface is by subclassing the KeyAdapter class.

public abstract interface java.awt.event.KeyListener extends java.util.EventListener{
// Public Instance Methods
public abstract void keyPressed (KeyEvent e);
public abstract void keyReleased (KeyEvent e);
public abstract void keyTyped (KeyEvent e);
}

EventListener interface in java

EventListener is a base interface for the Java AWT event model. This interface defines no method or constants. Its purpose is to serve as a tag to identify objects that serve as event listeners. The event listener interfaces in the java.awt.event and java.beans packages extend this interface.

public interface java.util.EventListener {}
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 28
  • 34
  • 28
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    137
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here