home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Gallery
/
INTERGAL.bin
/
intergal
/
prgs
/
idv21
/
data.z
/
javaeyes.java
< prev
next >
Wrap
Text File
|
1995-10-08
|
4KB
|
187 lines
import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;
import java.awt.Event;
/*
JavaEyes version 1.0
Written by Arjan van de Ven
Burg.Schafratstr. 38
5427 SR Boekel
The Netherlands
+31-4922-322320
arjan@stack.urc.tue.nl
This applet is released to the Public Domain
*/
public class Javaeyes extends java.applet.Applet implements Runnable
{
Thread runner;
int lX = 40;
int lY = 40;
int rX = 70;
int rY = 40;
int lEyeX=-1,rEyeX=-1,lEyeY=-1,rEyeY=-1;
boolean rPoked=false, lPoked=false;
boolean sleeping = false;
public void start()
{
if (runner==null)
{
runner = new Thread(this);
runner.start();
}
}
public void stop()
{
if (runner!=null)
{
runner.stop(); runner=null;
}
}
public void run()
{
while (true)
{
try
{
Thread.sleep(1000);
}
catch ( InterruptedException e)
{
}
}
}
public void paint(Graphics g)
{
if (lPoked && (sleeping==false))
{
g.setColor(ALeftpushcolor);
}
else
{
g.setColor(ALeftopencolor);
}
g.fillOval(lX+1,lY+1,19,19);
if (rPoked && (sleeping==false))
{
g.setColor(ARightpushcolor);
}
else
{
g.setColor(ARightopencolor);
}
g.fillOval(rX+1,rY+1,19,19);
g.setColor(Color.black);
g.drawOval(lX,lY,20,20);
g.drawOval(rX,rY,20,20);
if ((sleeping == false) && (lEyeX>=0))
{
g.fillOval(lEyeX,lEyeY,6,6);
g.fillOval(rEyeX,rEyeY,6,6);
}
else
{
//g.drawLine(lX,lY+10,lX+20,lY+10);
//g.drawLine(rX,rY+10,rX+20,rY+10);
g.drawArc(rX,rY+4,20,10,0,-180);
g.drawArc(lX,lY+4,20,10,0,-180);
}
}
public void update(Graphics g)
{
paint(g);
}
public boolean mouseDown(Event evt, int x, int y)
{
float dx,dy;
float length;
dx = 1.0f * (x - lX-10);
dy = 1.0f * (y - lY-10);
length = (float) (Math.sqrt(dx*dx + dy*dy));
if (length<8)
{
lPoked = true;
repaint();
}
;
dx = 1.0f * (x - rX-10);
dy = 1.0f * (y - rY-10);
length = (float) (Math.sqrt(dx*dx + dy*dy));
if (length<8)
{
rPoked = true;repaint();
}
;
return false;
}
public boolean mouseMove(Event evt, int x, int y)
{
float dx,dy;
float length;
int _lEyeX,_lEyeY;
int _rEyeX,_rEyeY;
dx = 1.0f * (x - lX-10);
dy = 1.0f * (y - lY-10);
length = (float) (Math.sqrt(dx*dx + dy*dy));
if (length>7)
{
dx = dx * (7 / length);
dy = dy * (7 / length);
}
_lEyeX = (int) (lX + dx+10-2);
_lEyeY = (int) (lY + dy+10-2);
dx = 1.0f * (x - rX-10);
dy = 1.0f * (y - rY-10);
length = (float) (Math.sqrt(dx*dx + dy*dy));
if (length>7)
{
dx = dx * (7 / length);
dy = dy * (7 / length);
}
_rEyeX = (int) (rX + dx+10-2);
_rEyeY = (int) (rY + dy+10-2);
if ((_rEyeX != rEyeX) || (_rEyeY != rEyeY) ||
(_lEyeX != lEyeX) || (_lEyeY != lEyeY))
{
rEyeX = _rEyeX;
rEyeY = _rEyeY;
lEyeX = _lEyeX;
lEyeY = _lEyeY;
repaint();
}
return false;
}
public boolean mouseEnter(Event evt, int x, int y)
{
sleeping = false;
repaint();
return false;
}
public boolean mouseExit(Event evt, int x, int y)
{
sleeping = true;
repaint();
lPoked =false;
rPoked = false;
return false;
}
}