import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class Java鼠标事件 {
public static void main(String[] args) {
Frame f = new Frame("WindowEvent");
f.setLayout(new FlowLayout());
f.setSize(300,200);
f.setLocation(300, 200);
f.setVisible(true);
Button btn = new Button("Button");
f.add(btn);
btn.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
System.out.println("MouseClicked--鼠标完成点击事件");
if(e.getButton()==e.BUTTON1) {
System.out.println("鼠标左击事件");
}
else if(e.getButton()==e.BUTTON2) {
System.out.println("鼠标中键点击事件");
}
else if (e.getButton()==e.BUTTON3) {
System.out.println("鼠标右击事件");
}
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
System.out.println("MouseEntered--鼠标进入按钮区域事件");
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
System.out.println("MouseExited--鼠标移出按钮区域事件");
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
System.out.println("MousePressed--鼠标按下事件");
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
System.out.println("MouseReleased--鼠标放开事件");
}
});
}
}