1、鼠标按下 、松开 、进入、移除等时发生动作事件

方法摘要:

MouseClicked

void mouseClicked(MouseEvent e)   鼠标按键在组件上单击(按下并释放)时调用。 

mousePressed

void mousePressed(MouseEvent e)   鼠标按键在组件上按下时调用。  

mouseReleased

void mouseReleased(MouseEvent e)    鼠标按钮在组件上释放时调用。  

mouseEntered

void mouseEntered(MouseEvent e)    鼠标进入到组件上时调用。

mouseExited

void mouseExited(MouseEvent e)    鼠标离开组件时调用。  

 

 


1
public class TestMouseList extends Frame 2 { 3 public static void main(String[] args) 4 { 5 Frame f = new Frame(); 6 f.setBounds(200, 200, 200, 200);//设置窗口的大小 位置 7 f.addMouseListener(new MouseListTest()); 8 f.setVisible(true);//让窗口显示出来 9 } 10 } 11 class MouseListTest implements MouseListener 12 { 13 @Override 14 public void mouseClicked(MouseEvent e) { 15 //System.out.println("点击事件"); 16 //System.out.println(e.getClickCount());//和鼠标抬起差不多 17 } 18 @Override 19 public void mousePressed(MouseEvent e) { 20 //System.out.println("鼠标按下"); 21 } 22 @Override 23 public void mouseReleased(MouseEvent e) { 24 //System.out.println("鼠标抬起"); 25 } 26 @Override 27 public void mouseEntered(MouseEvent e) { 28 System.out.println("鼠标进来了"); 29 } 30 @Override 31 public void mouseExited(MouseEvent e) { 32 System.out.println("鼠标出去了"); 33 } 34 35 }