import java.awt.*;
import java.applet.*;
import java.lang.*;
public class OneArrow extends Applet
{
Graphics bG;
Graphics sG;
Image bI;
Color back = new Color(247, 243, 234);
Color gback = new Color(192, 192, 255);
Color glines = new Color(0, 0, 255);
Color black = new Color(0, 0, 0);
int x = -1;
int y = -1;
int dx, dy;
double sx, sy, mag;
double p, q;
public void init()
{
bI = createImage(this.size().width, this.size().height);
bG = bI.getGraphics();
drawback();
}
public void paint(Graphics g)
{
g.drawImage(bI, 0, 0, this);
sG = getGraphics();
}
public void update(Graphics g)
{
g.drawImage(bI, 0, 0, this);
}
public void drawback()
{
bG.setColor(back);
bG.fillRect(0, 0, 211, 211);
bG.setColor(gback);
bG.fillRect(5, 5, 201, 201);
bG.setColor(glines);
for (int i = 0; i < 201; i = i + 20)
{
bG.drawLine(i + 5, 5, i + 5, 210);
bG.drawLine(0, i + 5, 205, i + 5);
}
if (x > -0.001)
{
bG.setColor(black);
bG.fillOval(x - 3, y - 3, 7, 7);
}
}
public boolean mouseDown(Event evt, int mx, int my)
{
if ((my > 4) && (my < 206) && (mx > 4) && (mx < 206))
{
x = mx;
y = my;
p = x - 5;
q = 205 - y;
sx = 0.50 * (1 - 0.01 * p - 0.005 * q) * p;
sy = 0.50 * (1 - 0.005 * p - 0.01 * q) * q;
drawback();
mag = java.lang.Math.sqrt(sx * sx + sy * sy);
if (mag > 0.0001)
{
dx = (int) java.lang.Math.round(20.0 * sx/mag);
dy = (int) java.lang.Math.round(20.0 * sy/mag);
bG.drawLine(x, y, x + dx, y - dy);
}
sG.drawImage(bI, 0, 0,this);
}
return true;
}
}
Copyright c 1997 by
Frank Wattenberg, Department of Mathematics, Montana State University,
Bozeman, MT 59717