1、鼠标按下 、松开 、进入、移除等时发生动作事件
方法摘要:
MouseClicked
void mouseClicked(MouseEvent
mousePressed
void mousePressed(MouseEvent
mouseReleased
void mouseReleased(MouseEvent
mouseEntered
void mouseEntered(MouseEvent
mouseExited
void mouseExited(MouseEvent
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 }