forked from vizay08/Java_physics_library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EyeApplet.java
49 lines (47 loc) · 1008 Bytes
/
EyeApplet.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
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
//<applet code="EyeApplet" width=900 height=750></applet>
public class EyeApplet extends Applet implements MouseMotionListener
{
int x,y,xold,yold;
public void init()
{
x=0;
y=0;
xold=0;yold=0;
addMouseMotionListener(this);
setBackground(Color.white);
}
public void mouseMoved(MouseEvent e)
{
x=e.getX();
y=e.getY();
showStatus("Mouse is at "+x+" , "+y);
repaint();
}
public void mouseDragged(MouseEvent e)
{
}
synchronized public void paint(Graphics g)
{
setForeground(Color.black);
g.drawOval(500,212,400,400);
if(x>502&&x<897&&y>214&&y<600)
g.fillOval(643,355,100,100);
else if(x<507&&xold<507)
{
if(y<17)
g.fillOval(543+((x-xold)/3),255-((y+yold)/3),100,100);
else
g.fillOval(543+((x-xold)/3),255+((y+yold)/3),100,100);
}
else
{
if(y<17)
g.fillOval(297-((xold-x)/3),255-((y+yold)/3),100,100);
else
g.fillOval(297-((xold-x)/3),255+((y+yold)/3),100,100);
}
}
}