-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUse Of MouseListener
57 lines (47 loc) · 1.21 KB
/
Use Of MouseListener
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
import java.applet.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class applet_class extends Applet implements MouseListener
{
int x,y;
String str = "null";
public void init()
{
addMouseListener(this);
}
@Override
public void mouseClicked(MouseEvent e) //when a mouse is clicked within in the applet
{
x=e.getX(); //to take x axis
y=e.getY(); //to take y axis
showStatus("Mouse Clicked at ("+x+","+y+")");
str = "Mouse Clicked at ("+x+","+y+")";
repaint(); //to call paint method
}
@Override
public void mouseEntered(MouseEvent e) //when mouse come back to applet
{
showStatus("Mouse Entered");
}
@Override
public void mouseExited(MouseEvent e) //when mouse exit from an applet
{
showStatus("Mouse Exited");
}
@Override
public void mousePressed(MouseEvent e) //when you press something within the applet
{
showStatus("Mouse Pressed");
}
@Override
public void mouseReleased(MouseEvent e) //when you released the mouse
{
showStatus("Mouse Released");
}
public void paint(Graphics g) //draw graphics or o/p to the screen
{
g.setFont(new Font("Times New Roman",Font.BOLD,50));
g.drawString(str, 120, 120);
}
}