home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.awt.Rectangle;
-
- public class MouseRun extends Applet implements Runnable {
- Point mouse = new Point(0, 0);
- Rectangle rectangle = new Rectangle(20, 20);
- Rectangle bounds = new Rectangle();
- Point vector = new Point(1, 1);
- // $FF: renamed from: me java.lang.Thread
- Thread field_0;
- int onaroll;
-
- public void start() {
- if (this.field_0 == null) {
- this.field_0 = new Thread(this);
- this.field_0.start();
- }
-
- }
-
- public void stop() {
- this.field_0 = null;
- }
-
- public boolean mouseMove(Event evt, int nX, int nY) {
- this.mouse.move(nX, nY);
- return true;
- }
-
- public boolean mouseDown(Event evt, int nX, int nY) {
- this.mouse.move(nX, nY);
- if (this.rectangle.inside(nX, nY)) {
- switch (++this.onaroll) {
- case 1:
- ((Applet)this).getAppletContext().showStatus("HIT IT AGAIN! AGAIN!");
- break;
- case 2:
- case 3:
- case 4:
- ((Applet)this).getAppletContext().showStatus("YOU'RE ON A ROLL:" + this.onaroll + "Hits!");
- break;
- default:
- ((Applet)this).getAppletContext().showStatus("You're on your way to THE HALL OF FAME:" + this.onaroll + "Hits!");
- }
-
- ((Applet)this).play(((Applet)this).getCodeBase(), "sounds/that.hurts.au");
- } else {
- ((Applet)this).getAppletContext().showStatus("You missed at (" + nX + ", " + nY + ")");
- ((Applet)this).play(((Applet)this).getCodeBase(), "sounds/thin.bell.au");
- this.onaroll = 0;
- }
-
- return true;
- }
-
- public void run() {
- for(; this.field_0 != null; ((Component)this).repaint()) {
- try {
- Thread.sleep(20L);
- } catch (InterruptedException var3) {
- this.field_0 = null;
- }
- }
-
- }
-
- public void init() {
- this.bounds.resize(((Component)this).size().width - 1, ((Component)this).size().height - 1);
- }
-
- public void paint(Graphics g) {
- g.drawRect(0, 0, this.bounds.width, this.bounds.height);
- Point center = new Point(this.rectangle.x + this.rectangle.width / 2, this.rectangle.y + this.rectangle.height / 2);
- this.vector.x = -1;
- if (this.mouse.x < center.x) {
- this.vector.x = 1;
- }
-
- if ((center.x - this.mouse.x) * this.vector.x > 100) {
- this.vector.x = 0;
- }
-
- this.vector.y = -1;
- if (this.mouse.y < center.y) {
- this.vector.y = 1;
- }
-
- if ((center.y - this.mouse.y) * this.vector.y > 100) {
- this.vector.y = 0;
- }
-
- this.rectangle.translate(this.vector.x, this.vector.y);
- Rectangle intersect = this.rectangle.intersection(this.bounds);
- if (!intersect.equals(this.rectangle)) {
- this.rectangle.move(this.bounds.width / 2, this.bounds.height / 2);
- }
-
- g.drawRect(this.rectangle.x, this.rectangle.y, this.rectangle.width, this.rectangle.height);
- }
- }
-