Anonymous Listener can be passed in the argument of addXYZListner() method. This anonymous class must consist of all the method.


  1. Components/Event Sources can be easily accessed from Listener methods
  2. To apply an event we have to pass anonymous object of Listener Interface
  3. Logic is to be written in complex inner methods
  4. All the methods must be defined. Blank definition is to be given even if we don’t want to use it.


import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class EventDemo3 extends Applet
	Button btn;
	Label lbl;
	public void init()
		btn = new Button("Click Me!");
		lbl = new Label("          ");

		btn.addMouseListener(new MouseListener()
			public void mouseClicked(MouseEvent e){ lbl.setText("Clicked!"); } 
			public void mouseEntered(MouseEvent e){}
			public void mouseExited(MouseEvent e){}
			public void mousePressed(MouseEvent e){} 
			public void mouseReleased(MouseEvent e){}			
<applet code="EventDemo3" width="500" height="50"></applet>