import java.awt.*;
import java.awt.event.*;
public class ThreeListener implements MouseMotionListener,MouseListener,WindowListener
{
private Frame f;
private TextField tf;
private static int counter=0;
public static void main(String agr[])
{
ThreeListener two= new ThreeListener();
two.go();
}
public void go()
{
f=new Frame("Three listeners example");
f.add(new Label("Click and drag the mouse"),"North");
tf=new TextField(30);
f.add(tf,"South");
f.addMouseListener(this);
f.addMouseMotionListener(this);
f.addWindowListener(this);
f.setSize(300,200);
f.setVisible(true);
}
public void mouseDragged(MouseEvent e)
{
String s="Mouse dragging;X="+e.getX()+"Y="+e.getY();
tf.setText(s);
}
public void mouseMoved(MouseEvent e)
{
String s="Mouse is moving and the position is X="+e.getX()+"Y="+e.getY();
tf.setText(s);
}
public void mouseClicked(MouseEvent e)
{
counter+=1;
String s="The times of click is "+counter;
tf.setText(s);
}
public void mouseEntered(MouseEvent e)
{
String s="The mouse entered";
tf.setText(s);
}
public void mouseExited(MouseEvent e)
{
String s="The mouse has left the building";
tf.setText(s);
}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void windowClosing(WindowEvent e)
{
System.out.println("window will be closed");
System.exit(0);
}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e)
{
System.out.println("what is the meaning???");
}
public void windowClosed(WindowEvent e)
{
System.out.println("window has been closed");
}
public void windowActivated(WindowEvent e)
{
System.out.println("window has been Activated");
}
public void windowDeactivated(WindowEvent e)
{
System.out.println("window has been deactivated");
}
public void windowOpened(WindowEvent e)
{
System.out.println("Window has been opened");
}
}