home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 October / DPPCPRO1098.ISO / Hotdog / files / snagpack.exe / SNAKETEXT.CLASS (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-21  |  5.0 KB  |  254 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 snaketext extends Applet implements Runnable {
  12.    private char[] separated;
  13.    private int stringLength;
  14.    private Thread engine;
  15.    private boolean userPause;
  16.    private int x_coord;
  17.    private int y_coord;
  18.    private int cur_x;
  19.    private int cur_y;
  20.    private int stepx = 10;
  21.    private int stepy = 1;
  22.    private int sleepTime;
  23.    private boolean threadSuspended;
  24.    private boolean debug;
  25.    private myFont font;
  26.    private int fontsize = 20;
  27.    private int fontstyle;
  28.    // $FF: renamed from: up boolean
  29.    private boolean field_0 = true;
  30.    private boolean ascend = true;
  31.    private boolean forward;
  32.    private boolean dir_right = true;
  33.    private Color foreGroundColor;
  34.    private Color backGroundColor;
  35.    private Image offScrImage;
  36.    private Graphics offScrGraphics;
  37.    private Dimension offScrSize;
  38.    private boolean matched;
  39.    private boolean unreg = true;
  40.  
  41.    public void stop() {
  42.       if (this.engine != null && this.engine.isAlive()) {
  43.          this.engine.stop();
  44.       }
  45.  
  46.       this.engine = null;
  47.    }
  48.  
  49.    private synchronized void detecter(int var1, int var2, int var3) {
  50.       this.x_coord = this.forward ? this.x_coord - var1 : this.x_coord + var1;
  51.       this.y_coord = this.field_0 ? this.y_coord - this.stepy : this.y_coord + this.stepy;
  52.       if (this.y_coord <= 0 + var3) {
  53.          this.field_0 = false;
  54.          this.y_coord += this.stepy;
  55.       } else if (this.y_coord >= ((Component)this).size().height) {
  56.          this.field_0 = true;
  57.          this.y_coord -= this.stepy;
  58.       }
  59.  
  60.       if (this.x_coord <= 0) {
  61.          this.forward = false;
  62.          this.x_coord = 0 - this.x_coord;
  63.       } else if (this.x_coord + var2 >= ((Component)this).size().width) {
  64.          this.forward = true;
  65.          this.x_coord = ((Component)this).size().width - (var2 + (this.x_coord + var2 - ((Component)this).size().width));
  66.       }
  67.  
  68.    }
  69.  
  70.    public void paint(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.  
  77.       for(int var3 = 0; var3 < this.stringLength; ++var3) {
  78.          var1.drawChars(this.separated, var3, 1, this.x_coord, this.y_coord);
  79.          if (!this.forward) {
  80.             if (var3 < this.stringLength - 1) {
  81.                this.detecter(var2.charsWidth(this.separated, var3, 1), var2.charsWidth(this.separated, var3 + 1, 1), var2.getAscent());
  82.             } else {
  83.                this.detecter(var2.charsWidth(this.separated, var3, 1), 0, var2.getAscent());
  84.             }
  85.          } else if (var3 < this.stringLength - 1) {
  86.             this.detecter(var2.charsWidth(this.separated, var3 + 1, 1), 0, var2.getAscent());
  87.          }
  88.       }
  89.  
  90.       this.cur_x = this.dir_right ? this.cur_x + this.stepx : this.cur_x - this.stepx;
  91.       int var4 = var2.charsWidth(this.separated, 0, 1);
  92.       if (this.dir_right && this.cur_x + var4 >= ((Component)this).size().width) {
  93.          this.dir_right = false;
  94.          this.cur_x = ((Component)this).size().width - (var4 + (this.cur_x + var4 - ((Component)this).size().width));
  95.       } else if (this.cur_x <= 0) {
  96.          this.dir_right = true;
  97.          this.cur_x = 0 - this.cur_x;
  98.       }
  99.  
  100.       if (this.y_coord <= 0) {
  101.          this.field_0 = false;
  102.       } else if (this.y_coord >= ((Component)this).size().height) {
  103.          this.field_0 = true;
  104.       }
  105.  
  106.       this.forward = !this.dir_right;
  107.       this.x_coord = this.cur_x;
  108.    }
  109.  
  110.    private void dbg(String var1) {
  111.       if (this.debug) {
  112.          System.out.println(var1);
  113.       }
  114.  
  115.    }
  116.  
  117.    public synchronized void update(Graphics var1) {
  118.       Dimension var2 = ((Component)this).size();
  119.       if (this.offScrImage == null || var2.width != this.offScrSize.width || var2.height != this.offScrSize.height) {
  120.          this.offScrImage = ((Component)this).createImage(var2.width, var2.height);
  121.          this.offScrGraphics = this.offScrImage.getGraphics();
  122.          this.offScrGraphics.setFont(((Component)this).getFont());
  123.          this.offScrSize = var2;
  124.       }
  125.  
  126.       this.offScrGraphics.fillRect(0, 0, var2.width, var2.height);
  127.       this.paint(this.offScrGraphics);
  128.       var1.drawImage(this.offScrImage, 0, 0, (ImageObserver)null);
  129.    }
  130.  
  131.    public void start() {
  132.       if (this.engine == null) {
  133.          this.engine = new Thread(this);
  134.       }
  135.  
  136.       this.engine.start();
  137.    }
  138.  
  139.    public String getAppletInfo() {
  140.       return "snaketext.class v1.1 Copyright Sausage SoftWare 1996";
  141.    }
  142.  
  143.    public void run() {
  144.       this.dbg("entered run");
  145.       Thread.currentThread().setPriority(1);
  146.  
  147.       while(true) {
  148.          if (this.unreg) {
  149.             ((Applet)this).getAppletContext().showStatus("Unregistered version. Copyright (c) Sausage Software 1996");
  150.          }
  151.  
  152.          ((Component)this).repaint();
  153.  
  154.          try {
  155.             Thread.sleep((long)this.sleepTime);
  156.          } catch (Exception var1) {
  157.          }
  158.       }
  159.    }
  160.  
  161.    public void init() {
  162.       String var1 = ((Applet)this).getParameter("font");
  163.       Object var2 = null;
  164.       String var14 = myFont.getFontName(var1);
  165.       this.dbg(var14);
  166.       var1 = ((Applet)this).getParameter("fontsize");
  167.       if (var1 != null) {
  168.          this.fontsize = Integer.parseInt(var1);
  169.       }
  170.  
  171.       var1 = ((Applet)this).getParameter("style");
  172.       this.fontstyle = myFont.getFontStyle(var1);
  173.       this.font = new myFont(var14, this.fontstyle, this.fontsize);
  174.       var1 = ((Applet)this).getParameter("color");
  175.       if (var1 != null) {
  176.          createColor var3 = new createColor(var1, ",");
  177.          this.foreGroundColor = var3.getColor();
  178.       } else {
  179.          this.foreGroundColor = new Color(255, 0, 0);
  180.       }
  181.  
  182.       var1 = ((Applet)this).getParameter("background");
  183.       if (var1 != null) {
  184.          createColor var15 = new createColor(var1, ",");
  185.          this.backGroundColor = var15.getColor();
  186.       } else {
  187.          this.backGroundColor = new Color(0, 0, 0);
  188.       }
  189.  
  190.       String var16 = ((Applet)this).getParameter("text");
  191.       if (var16 == null) {
  192.          var16 = "Sausage Software";
  193.       }
  194.  
  195.       this.stringLength = var16.length();
  196.       String var4 = ((Applet)this).getParameter("reguser");
  197.       if (var4 == null) {
  198.          ver.NotRegistered();
  199.       }
  200.  
  201.       if (var4.toLowerCase().equals("unregistered")) {
  202.          this.unreg = true;
  203.       } else {
  204.          this.unreg = false;
  205.       }
  206.  
  207.       String var5 = ((Applet)this).getParameter("serialid");
  208.       if (var5 == null) {
  209.          ver.NotRegistered();
  210.       }
  211.  
  212.       ver var6 = new ver(var4, var5);
  213.       this.matched = var6.verifyUser(var16);
  214.       if (!this.matched) {
  215.          ver.NotRegistered();
  216.       }
  217.  
  218.       var1 = ((Applet)this).getParameter("horizontal");
  219.       if (var1 != null) {
  220.          this.stepx = Integer.valueOf(var1);
  221.       }
  222.  
  223.       var1 = ((Applet)this).getParameter("vertical");
  224.       if (var1 != null) {
  225.          this.stepy = Integer.valueOf(var1);
  226.       }
  227.  
  228.       var1 = ((Applet)this).getParameter("speed");
  229.       if (var1 != null) {
  230.          this.sleepTime = Integer.parseInt(var1);
  231.       }
  232.  
  233.       this.separated = new char[this.stringLength];
  234.       var16.getChars(0, var16.length(), this.separated, 0);
  235.       this.x_coord = this.cur_x = 0;
  236.       this.y_coord = this.cur_y = ((Component)this).size().height;
  237.       this.dbg("finish init");
  238.    }
  239.  
  240.    public boolean handleEvent(Event var1) {
  241.       if (var1.id == 501) {
  242.          if (this.userPause) {
  243.             this.engine.resume();
  244.          } else {
  245.             this.engine.suspend();
  246.          }
  247.  
  248.          this.userPause = !this.userPause;
  249.       }
  250.  
  251.       return true;
  252.    }
  253. }
  254.