-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouseex.java
100 lines (76 loc) · 1.92 KB
/
mouseex.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package demo;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class mouseex extends WindowAdapter implements MouseListener,MouseMotionListener
{
Label label1, label2;
Frame frame;
String str;
mouseex()
{
frame = new Frame("Window");
label1= new Label("Handling mouse events in the Frame window", Label.CENTER);
label2= new Label();
Point p;
frame.setLayout(new FlowLayout());
frame.add(label1);
frame.add(label2);
//Registering class MouseEx1 to catch and respond to mouse events
frame.addMouseListener(this);
frame.addMouseMotionListener(this);
//Registering class MouseEx3 to catch and respond to window event i.e. window closing event
frame.addWindowListener(this);
frame.setSize(340,200);
frame.setVisible(true);
}
public void mouseClicked(MouseEvent we)
{
str+=" and Mouse button was clicked";
label2.setText(str);
frame.setVisible(true);
}
public void mouseEntered(MouseEvent we)
{
label2.setText("Mouse has entered the window area");
frame.setVisible(true);
}
public void mouseExited(MouseEvent we)
{
label2.setText("Mouse has exited the window area");
frame.setVisible(true);
}
public void mousePressed(MouseEvent we)
{
label2.setText("Mouse button is being pressed");
frame.setVisible(true);
}
public void mouseReleased(MouseEvent we)
{
str="Mouse button is released";
label2.setText(str);
frame.setVisible(true);
}
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
//Method of MouseMotionListener interface
public void mouseDragged(MouseEvent me)
{
String s = me.getX() + "," + me.getY();
label2.setText("Mouse dragged "+ s);
frame.setVisible(true);
}
//Method of MouseMotionListener interface
public void mouseMoved(MouseEvent me)
{
String s = me.getX() + "," + me.getY();
label2.setText("Mouse moved "+ s);
frame.setVisible(true);
}
public static void main(String... ar)
{
new mouseex();
}
}