-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMouseEvents2.java
46 lines (41 loc) · 986 Bytes
/
MouseEvents2.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
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code=MouseEvents2 width=300 height=100>
</applet>
*/
public class MouseEvents2 extends Applet implements MouseListener
{
String msg = "";
int mouseX = 0, mouseY = 0; // coordinates of mouse
public void init()
{
addMouseListener(this);
}
// Handle mouse clicked.
public void mouseClicked(MouseEvent me)
{
// save coordinates
mouseX = me.getX();
mouseY = me.getY();
msg = "Mouse clicked"+ mouseX + ", " + mouseY;
showStatus("MOUSE CLICKED AT" + mouseX + ", " + mouseY);
repaint();
}
// Handle mouse entered.
public void mouseEntered(MouseEvent me)
{
}
// Handle mouse exited.
public void mouseExited(MouseEvent me) {
}
// Handle button released.
public void mouseReleased(MouseEvent me) {
}
public void mousePressed(MouseEvent me) {
}
public void paint(Graphics g) {
g.drawString(msg, mouseX, mouseY);
}
}