Tags

This code was implemented for testing we can add two listeners to manage same event.

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class DoubleListener extends Applet {

	private static final long serialVersionUID = 2371255015431000864L;

	public void init()	{
		System.out.println("Init");
		this.addMouseListener(new MyMouseListener1());
		this.addMouseListener(new MyMouseListener2());
	}

	public DoubleListener()	{
		super();
		setSize(600,900);
		setVisible(true);
	}

	public void paint(Graphics g) {
		g.setColor(Color.WHITE);
		g.fillRect(0, 0, getWidth(), getHeight());
	}

}

class MyMouseListener1 implements MouseListener	{
	public void mouseClicked(MouseEvent e) {
		System.out.println("MyMouseListener1::click()");
	}
	public void mouseEntered(MouseEvent e) {	}
	public void mouseExited(MouseEvent e)  {	}
	public void mousePressed(MouseEvent e) {	}
	public void mouseReleased(MouseEvent e) {	}
}

class MyMouseListener2 implements MouseListener	{
	public void mouseClicked(MouseEvent e) {
		System.out.println("MyMouseListener2::click()");
	}
	public void mouseEntered(MouseEvent e) {	}
	public void mouseExited(MouseEvent e)  {	}
	public void mousePressed(MouseEvent e) {	}
	public void mouseReleased(MouseEvent e) {	}
}
Advertisements