home *** CD-ROM | disk | FTP | other *** search
/ Learn Java Now / Learn_Java_Now_Microsoft_1996.iso / JavaNow / Code / AppB / JumpingBox / MouseTrack.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-07-09  |  2.9 KB  |  87 lines

  1. import java.applet.Applet;
  2. import java.awt.Component;
  3. import java.awt.Event;
  4. import java.awt.Graphics;
  5.  
  6. public class MouseTrack extends Applet {
  7.    // $FF: renamed from: mx int
  8.    int field_0;
  9.    // $FF: renamed from: my int
  10.    int field_1;
  11.    int onaroll;
  12.  
  13.    public void mouseExit() {
  14.       this.onaroll = 0;
  15.       ((Component)this).repaint();
  16.    }
  17.  
  18.    public boolean mouseMove(Event evt, int x, int y) {
  19.       if (x % 3 == 0 && y % 3 == 0) {
  20.          ((Component)this).repaint();
  21.       }
  22.  
  23.       return true;
  24.    }
  25.  
  26.    public boolean mouseDown(Event evt, int x, int y) {
  27.       ((Component)this).requestFocus();
  28.       if (this.field_0 < x && x < this.field_0 + ((Component)this).size().width / 10 - 1 && this.field_1 < y && y < this.field_1 + ((Component)this).size().height / 10 - 1) {
  29.          if (this.onaroll > 0) {
  30.             switch (this.onaroll % 4) {
  31.                case 0:
  32.                   ((Applet)this).play(((Applet)this).getCodeBase(), "sounds/tiptoe.thru.the.tulips.au");
  33.                   break;
  34.                case 1:
  35.                   ((Applet)this).play(((Applet)this).getCodeBase(), "sounds/danger,danger...!.au");
  36.                   break;
  37.                case 2:
  38.                   ((Applet)this).play(((Applet)this).getCodeBase(), "sounds/adapt-or-die.au");
  39.                   break;
  40.                case 3:
  41.                   ((Applet)this).play(((Applet)this).getCodeBase(), "sounds/cannot.be.completed.au");
  42.             }
  43.  
  44.             ++this.onaroll;
  45.             if (this.onaroll > 5) {
  46.                ((Applet)this).getAppletContext().showStatus("You're on your way to THE HALL OF FAME:" + this.onaroll + "Hits!");
  47.             } else {
  48.                ((Applet)this).getAppletContext().showStatus("YOU'RE ON A ROLL:" + this.onaroll + "Hits!");
  49.             }
  50.          } else {
  51.             ((Applet)this).getAppletContext().showStatus("HIT IT AGAIN! AGAIN!");
  52.             ((Applet)this).play(((Applet)this).getCodeBase(), "sounds/that.hurts.au");
  53.             this.onaroll = 1;
  54.          }
  55.       } else {
  56.          ((Applet)this).getAppletContext().showStatus("You hit nothing at (" + x + ", " + y + "), exactly");
  57.          ((Applet)this).play(((Applet)this).getCodeBase(), "sounds/thin.bell.au");
  58.          this.onaroll = 0;
  59.       }
  60.  
  61.       ((Component)this).repaint();
  62.       return true;
  63.    }
  64.  
  65.    public void keyDown(int key) {
  66.       ((Component)this).requestFocus();
  67.       this.onaroll = 0;
  68.       ((Applet)this).play(((Applet)this).getCodeBase(), "sounds/ip.au");
  69.    }
  70.  
  71.    public void mouseEnter() {
  72.       ((Component)this).repaint();
  73.    }
  74.  
  75.    public void init() {
  76.       this.onaroll = 0;
  77.       ((Applet)this).resize(500, 500);
  78.    }
  79.  
  80.    public void paint(Graphics g) {
  81.       g.drawRect(0, 0, ((Component)this).size().width - 1, ((Component)this).size().height - 1);
  82.       this.field_0 = (int)(Math.random() * (double)1000.0F) % (((Component)this).size().width - ((Component)this).size().width / 10);
  83.       this.field_1 = (int)(Math.random() * (double)1000.0F) % (((Component)this).size().height - ((Component)this).size().height / 10);
  84.       g.drawRect(this.field_0, this.field_1, ((Component)this).size().width / 10 - 1, ((Component)this).size().height / 10 - 1);
  85.    }
  86. }
  87.