1import java.applet.Applet;
2import java.awt.*;
3import java.awt.event.*;
4
5public
6class MouseMotionApplet extends Applet {
7
8 Canvas c;
9 Label l;
10
11 public
12 void init () {
13
14
15
16
17 c = new Canvas();
18 c.setSize(300,100);
19 c.setBackground(Color.blue);
20
21 l = new Label();
22 l.setSize(300,30);
23 l.setBackground(Color.yellow);
24 l.setAlignment(Label.LEFT);
25
26
27
28
29
30 c.addMouseMotionListener
31 (new MouseMotionAdapter()
32 {
33 public
34 void mouseMoved(MouseEvent e) {
35 mouseStatus("mouse at",e.getX(),e.getY());
36 }
37 public
38 void mouseDragged(MouseEvent e) {
39 mouseStatus("mouse dragged at",e.getX(),e.getY());
40 }
41 }
42 );
43
44
45
46
47
48 c.addMouseListener
49 (new MouseAdapter()
50 {
51 public
52 void mousePressed(MouseEvent e) {
53 mouseStatus("mouse pressed at",e.getX(),e.getY());
54 }
55 public
56 void mouseReleased(MouseEvent e) {
57 mouseStatus("mouse released at",e.getX(),e.getY());
58 }
59 public
60 void mouseEntered(MouseEvent e) {
61 mouseStatus("mouse entered at",e.getX(),e.getY());
62 }
63 public
64 void mouseExited(MouseEvent e) {
65 mouseStatus("mouse exited at",e.getX(),e.getY());
66 }
67 }
68 );
69
70
71
72
73 setLayout(new BorderLayout());
74 add("North",c);
75 add("South",l);
76 }
77
78
79
80
81 protected
82 void mouseStatus(String status,
83 int x,
84 int y) {
85 l.setText(status + " " + x + "," + y);
86 }
87}
88
89