import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class EventExample {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame f=new JFrame("simple frame");
Container cp=f.getContentPane();
cp.setLayout(new FlowLayout());
JButton b1=new JButton("ok");
JButton b2=new JButton("cancel");
cp.add(b1);
cp.add(b2);
MouseListener l=new ExampleMouseListener();
MouseMotionListener m=new ExampleMouseListener();
b1.addMouseListener(l);
b2.addMouseListener(l);
b1.addMouseMotionListener(m);
b2.addMouseMotionListener(m);
f.pack();
f.setVisible(true);
}
}
class ExampleMouseListener implements MouseListener, MouseMotionListener
{
//MouseListener interface
public void mousePressed(MouseEvent evt)
{
System.out.println("Mouse pressed:"+ evt);
}
public void mouseReleased(MouseEvent evt)
{
System.out.println("Mouse released:"+evt);
}
public void mouseClicked(MouseEvent evt)
{
System.out.println("Mouse clicked:"+evt);
}
public void mouseEntered(MouseEvent evt)
{
System.out.println("Mouse entered:"+evt);
}
public void mouseExited(MouseEvent evt)
{
System.out.println("Mouse exited:"+evt);
}
//mousemotionlistener interface
public void mouseMoved(MouseEvent evt)
{
System.out.println("Mouse moved:"+evt);
}
public void mouseDragged(MouseEvent evt)
{
System.out.println("Mouse dragged:"+evt);
}
}