home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 October / DPPCPRO1098.ISO / Hotdog / files / snagpack.exe / BOUNCE.CLASS (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-21  |  4.9 KB  |  240 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Dimension;
  5. import java.awt.Event;
  6. import java.awt.FontMetrics;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.awt.image.ImageObserver;
  10.  
  11. public class bounce extends Applet implements Runnable {
  12.    // $FF: renamed from: s java.lang.String
  13.    private String field_0;
  14.    private int stringLength;
  15.    private Thread engineThread;
  16.    private boolean userPause;
  17.    private boolean readyToPaint = true;
  18.    private Graphics offGraphics;
  19.    private Image offImage;
  20.    private int x_coord;
  21.    private int y_coord = 10;
  22.    private int sleepTime = 100;
  23.    private int stepx = 10;
  24.    private int stepy = 1;
  25.    private myFont font;
  26.    private int fontsize = 20;
  27.    private int fontstyle;
  28.    private Color foreGroundColor;
  29.    private Color backGroundColor;
  30.    // $FF: renamed from: up boolean
  31.    private boolean field_1 = true;
  32.    private boolean dir_right = true;
  33.    private boolean matched;
  34.    private boolean unreg = true;
  35.    private Dimension offScrSize;
  36.    private boolean debug;
  37.  
  38.    private synchronized void detecter(int var1, int var2) {
  39.       int var3 = this.dir_right ? this.x_coord + var1 + this.stepx : this.x_coord - this.stepx;
  40.       int var4 = this.field_1 ? this.y_coord - this.stepy - var2 : this.y_coord + this.stepy;
  41.       if (var4 <= 0) {
  42.          this.field_1 = false;
  43.       } else if (var4 >= ((Component)this).size().height) {
  44.          this.field_1 = true;
  45.       }
  46.  
  47.       if (var3 <= 0) {
  48.          this.dir_right = true;
  49.       } else if (var3 >= ((Component)this).size().width) {
  50.          this.dir_right = false;
  51.       }
  52.  
  53.       this.y_coord = this.field_1 ? this.y_coord - this.stepy : this.y_coord + this.stepy;
  54.       this.x_coord = this.dir_right ? this.x_coord + this.stepx : this.x_coord - this.stepx;
  55.    }
  56.  
  57.    public void stop() {
  58.       if (this.engineThread != null && this.engineThread.isAlive()) {
  59.          this.engineThread.stop();
  60.       }
  61.  
  62.       this.engineThread = null;
  63.    }
  64.  
  65.    private void NotRegistered() {
  66.       System.out.println("Program not registered");
  67.       System.exit(0);
  68.    }
  69.  
  70.    public synchronized void prePaint(Graphics var1) {
  71.       var1.setColor(this.backGroundColor);
  72.       var1.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  73.       var1.setFont(this.font);
  74.       var1.setColor(this.foreGroundColor);
  75.       FontMetrics var2 = var1.getFontMetrics();
  76.       var1.drawString(this.field_0, this.x_coord, this.y_coord);
  77.       this.detecter(var2.stringWidth(this.field_0), var2.getAscent() - var2.getLeading());
  78.    }
  79.  
  80.    public void paint(Graphics var1) {
  81.       if (this.engineThread != null) {
  82.          if (this.offGraphics != null) {
  83.             this.prePaint(this.offGraphics);
  84.             var1.drawImage(this.offImage, 0, 0, this);
  85.          } else {
  86.             this.prePaint(var1);
  87.          }
  88.       }
  89.  
  90.    }
  91.  
  92.    private void dbg(String var1) {
  93.       if (this.debug) {
  94.          System.out.println(var1);
  95.       }
  96.  
  97.    }
  98.  
  99.    public synchronized void update(Graphics var1) {
  100.       Dimension var2 = ((Component)this).size();
  101.       if (this.offImage == null || var2.width != this.offScrSize.width || var2.height != this.offScrSize.height) {
  102.          this.offImage = ((Component)this).createImage(var2.width, var2.height);
  103.          this.offGraphics = this.offImage.getGraphics();
  104.          this.offGraphics.setFont(((Component)this).getFont());
  105.          this.offScrSize = var2;
  106.       }
  107.  
  108.       if (this.readyToPaint) {
  109.          this.paint(this.offGraphics);
  110.          var1.drawImage(this.offImage, 0, 0, (ImageObserver)null);
  111.       }
  112.  
  113.    }
  114.  
  115.    public void start() {
  116.       if (this.engineThread == null) {
  117.          this.engineThread = new Thread(this);
  118.       }
  119.  
  120.       this.engineThread.start();
  121.    }
  122.  
  123.    public String getAppletInfo() {
  124.       return "Swami - bounce.class v1.0 Copyright (c)Sausage SoftWare 1996";
  125.    }
  126.  
  127.    public void run() {
  128.       Thread.currentThread().setPriority(1);
  129.  
  130.       while(true) {
  131.          if (this.unreg) {
  132.             ((Applet)this).getAppletContext().showStatus("Unregistered version. Copyright (c) Sausage Software 1996");
  133.          }
  134.  
  135.          ((Component)this).repaint();
  136.  
  137.          try {
  138.             Thread.sleep((long)this.sleepTime);
  139.          } catch (Exception var1) {
  140.          }
  141.       }
  142.    }
  143.  
  144.    public void init() {
  145.       this.field_0 = ((Applet)this).getParameter("text");
  146.       if (this.field_0 == null) {
  147.          this.field_0 = "Sausage Software";
  148.       }
  149.  
  150.       this.stringLength = this.field_0.length();
  151.       String var1 = ((Applet)this).getParameter("reguser");
  152.       if (var1 == null) {
  153.          this.NotRegistered();
  154.       }
  155.  
  156.       if (var1.toLowerCase().equals("unregistered")) {
  157.          this.unreg = true;
  158.       } else {
  159.          this.unreg = false;
  160.       }
  161.  
  162.       String var2 = ((Applet)this).getParameter("serialid");
  163.       if (var2 == null) {
  164.          this.NotRegistered();
  165.       }
  166.  
  167.       ver var3 = new ver(var1, var2);
  168.       this.matched = var3.verifyUser(this.field_0);
  169.       if (!this.matched) {
  170.          this.NotRegistered();
  171.       }
  172.  
  173.       String var4 = ((Applet)this).getParameter("font");
  174.       Object var5 = null;
  175.       String var15 = myFont.getFontName(var4);
  176.       this.dbg(var15);
  177.       var4 = ((Applet)this).getParameter("fontsize");
  178.       if (var4 != null) {
  179.          this.fontsize = Integer.parseInt(var4);
  180.       }
  181.  
  182.       var4 = ((Applet)this).getParameter("style");
  183.       this.fontstyle = myFont.getFontStyle(var4);
  184.       this.font = new myFont(var15, this.fontstyle, this.fontsize);
  185.       var4 = ((Applet)this).getParameter("color");
  186.       if (var4 != null) {
  187.          createColor var6 = new createColor(var4, ",");
  188.          this.foreGroundColor = var6.getColor();
  189.       } else {
  190.          this.foreGroundColor = new Color(255, 0, 0);
  191.       }
  192.  
  193.       var4 = ((Applet)this).getParameter("background");
  194.       if (var4 != null) {
  195.          createColor var16 = new createColor(var4, ",");
  196.          this.backGroundColor = var16.getColor();
  197.       } else {
  198.          this.backGroundColor = new Color(0, 0, 0);
  199.       }
  200.  
  201.       var4 = ((Applet)this).getParameter("horizontal");
  202.       if (this.field_0 != null) {
  203.          this.stepx = Integer.valueOf(var4);
  204.       }
  205.  
  206.       var4 = ((Applet)this).getParameter("vertical");
  207.       if (var4 != null) {
  208.          this.stepy = Integer.valueOf(var4);
  209.       }
  210.  
  211.       var4 = ((Applet)this).getParameter("speed");
  212.       if (var4 != null) {
  213.          this.sleepTime = Integer.parseInt(var4);
  214.       }
  215.  
  216.       var4 = ((Applet)this).getParameter("startPosition");
  217.       int var17 = var4 != null ? Integer.parseInt(var4) : 0;
  218.       this.x_coord = 0;
  219.       this.y_coord = ((Component)this).size().height - var17;
  220.       this.dbg("finish init");
  221.    }
  222.  
  223.    public boolean handleEvent(Event var1) {
  224.       if (var1.id == 501) {
  225.          if (this.userPause) {
  226.             this.engineThread.resume();
  227.          } else {
  228.             this.engineThread.suspend();
  229.          }
  230.  
  231.          this.userPause = !this.userPause;
  232.       } else if (var1.id == 201) {
  233.          this.stop();
  234.          System.exit(0);
  235.       }
  236.  
  237.       return true;
  238.    }
  239. }
  240.