home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 10: University / CDAT10.iso / TUTORIALES / ManualInternet / jumpman.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-04-03  |  7.8 KB  |  359 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Event;
  5. import java.awt.Font;
  6. import java.awt.FontMetrics;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.util.NoSuchElementException;
  10. import java.util.StringTokenizer;
  11.  
  12. public class jumpman extends Applet implements Runnable {
  13.    private Thread engineThread;
  14.    private String lbl;
  15.    private char[] label;
  16.    private int stringLen;
  17.    private int count;
  18.    private int loop;
  19.    private int speed;
  20.    private int sleepTime = 50;
  21.    private int jumpheight;
  22.    private Font font;
  23.    private boolean userPause = false;
  24.    private String reguser;
  25.    private String serialid;
  26.    private int passkey;
  27.    private Color fgColor;
  28.    private Color bgColor;
  29.    private int red = 255;
  30.    private int blue;
  31.    private int green;
  32.    private int fade;
  33.    private int jump_char;
  34.    private int movey;
  35.    private boolean yUp = true;
  36.    private boolean readyToPaint;
  37.    private boolean popcorn = false;
  38.    private int height;
  39.    // $FF: renamed from: x int
  40.    private int field_0;
  41.    // $FF: renamed from: y int
  42.    private int field_1;
  43.    // $FF: renamed from: fm java.awt.FontMetrics
  44.    private FontMetrics field_2;
  45.    private Image offImage;
  46.    private Graphics offGraphics;
  47.    private boolean matched = false;
  48.    private boolean unreg = true;
  49.    private boolean debug = false;
  50.  
  51.    public String getAppletInfo() {
  52.       return "HotDog3 - jumpman.class v1.0 Copyright Sausage SoftWare 1996";
  53.    }
  54.  
  55.    private void dbg(String var1) {
  56.       if (this.debug) {
  57.          System.out.println(var1);
  58.       }
  59.  
  60.    }
  61.  
  62.    public void init() {
  63.       String var1 = ((Applet)this).getParameter("fontsize");
  64.       int var2 = var1 == null ? 12 : Integer.valueOf(var1);
  65.       int var3 = 0;
  66.       var1 = ((Applet)this).getParameter("style");
  67.       var3 = this.getFontStyle(var1);
  68.       var1 = ((Applet)this).getParameter("font");
  69.       String var4 = this.getFontName(var1);
  70.       this.dbg(var4);
  71.       this.font = new Font(var4, var3, var2);
  72.       var1 = ((Applet)this).getParameter("text");
  73.       this.lbl = var1 == null ? "Sausage Software" : var1;
  74.       this.label = this.lbl.toCharArray();
  75.       this.stringLen = this.lbl.length();
  76.       this.reguser = ((Applet)this).getParameter("reguser");
  77.       if (this.reguser == null) {
  78.          this.NotRegistered();
  79.       }
  80.  
  81.       if (this.reguser.toLowerCase().equals("unregistered")) {
  82.          this.unreg = true;
  83.       } else {
  84.          this.unreg = false;
  85.       }
  86.  
  87.       this.serialid = ((Applet)this).getParameter("serialid");
  88.       if (this.serialid == null) {
  89.          this.NotRegistered();
  90.       }
  91.  
  92.       this.matched = this.verifyUser(this.lbl);
  93.       if (!this.matched) {
  94.          this.NotRegistered();
  95.       }
  96.  
  97.       var1 = ((Applet)this).getParameter("jumpstep");
  98.       this.speed = var1 == null ? 100 : Integer.parseInt(var1);
  99.       var1 = ((Applet)this).getParameter("vertical");
  100.       this.jumpheight = var1 == null ? 10 : Integer.parseInt(var1);
  101.       var1 = ((Applet)this).getParameter("speed");
  102.       this.sleepTime = var1 == null ? 50 : Integer.parseInt(var1);
  103.       var1 = ((Applet)this).getParameter("popcorn");
  104.       if ("yes".equals(var1)) {
  105.          this.popcorn = true;
  106.       }
  107.  
  108.       var1 = ((Applet)this).getParameter("color");
  109.       if (var1 != null) {
  110.          this.fgColor = this.getColor(var1, ",");
  111.       }
  112.  
  113.       var1 = ((Applet)this).getParameter("background");
  114.       if (var1 != null) {
  115.          this.bgColor = this.getColor(var1, ",");
  116.       }
  117.  
  118.       try {
  119.          this.offImage = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
  120.       } catch (Exception var5) {
  121.          this.offGraphics = null;
  122.       }
  123.  
  124.       this.field_1 = ((Component)this).size().height / 2 + var2 / 2;
  125.       this.movey = this.field_1;
  126.       this.height = this.field_1 - this.jumpheight;
  127.    }
  128.  
  129.    private Color getColor(String var1, String var2) {
  130.       StringTokenizer var3 = new StringTokenizer(var1, var2);
  131.  
  132.       try {
  133.          int var5 = Integer.parseInt(var3.nextToken());
  134.          int var6 = Integer.parseInt(var3.nextToken());
  135.          int var7 = Integer.parseInt(var3.nextToken());
  136.          Color var4 = new Color(var5, var6, var7);
  137.          return var4;
  138.       } catch (NoSuchElementException var8) {
  139.          return new Color(255, 0, 0);
  140.       }
  141.    }
  142.  
  143.    private synchronized void prePaint(Graphics var1) {
  144.       var1.setColor(this.bgColor);
  145.       var1.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  146.       var1.setColor(this.fgColor);
  147.       var1.setFont(this.font);
  148.       this.field_2 = var1.getFontMetrics();
  149.       this.field_0 = ((Component)this).size().width / 2 - this.field_2.stringWidth(this.lbl) / 2;
  150.       this.dbg("movey" + this.movey);
  151.  
  152.       for(int var2 = 0; var2 < this.stringLen; ++var2) {
  153.          if (var2 != this.jump_char) {
  154.             var1.drawChars(this.label, var2, 1, this.field_0, this.field_1);
  155.          } else {
  156.             var1.drawChars(this.label, var2, 1, this.field_0, this.movey);
  157.          }
  158.  
  159.          this.field_0 += this.field_2.charWidth(this.label[var2]);
  160.       }
  161.  
  162.    }
  163.  
  164.    private synchronized void xyUpdate() {
  165.       if (this.yUp) {
  166.          this.movey -= this.speed;
  167.       } else {
  168.          this.movey += this.speed;
  169.       }
  170.  
  171.       if (this.movey < this.height) {
  172.          this.yUp = false;
  173.       } else if (this.movey > this.field_1) {
  174.          if (this.popcorn) {
  175.             this.jump_char = (int)(Math.random() * (double)100.0F % (double)this.stringLen);
  176.          } else {
  177.             ++this.jump_char;
  178.          }
  179.  
  180.          this.movey = this.field_1;
  181.          this.yUp = true;
  182.  
  183.          try {
  184.             while(Character.isSpace(this.label[this.jump_char])) {
  185.                ++this.jump_char;
  186.             }
  187.          } catch (ArrayIndexOutOfBoundsException var1) {
  188.          }
  189.       }
  190.  
  191.       if (this.jump_char > this.stringLen) {
  192.          this.jump_char = 0;
  193.       }
  194.  
  195.    }
  196.  
  197.    public void paint(Graphics var1) {
  198.       if (this.engineThread != null) {
  199.          if (this.matched) {
  200.             this.offGraphics = this.offImage.getGraphics();
  201.             this.prePaint(this.offGraphics);
  202.             this.offGraphics.dispose();
  203.             var1.drawImage(this.offImage, 0, 0, this);
  204.             return;
  205.          }
  206.  
  207.          var1.setColor(this.fgColor);
  208.          var1.drawString("Applet parameters have changed, please recompile with HotDog", 2, ((Component)this).size().height - 2);
  209.          ((Applet)this).showStatus("jumpman.class: Applet parameters have changed, please recompile with HotDog");
  210.       }
  211.  
  212.    }
  213.  
  214.    public void start() {
  215.       if (this.engineThread == null) {
  216.          this.engineThread = new Thread(this);
  217.       }
  218.  
  219.       this.engineThread.start();
  220.    }
  221.  
  222.    public void stop() {
  223.       if (this.engineThread != null && this.engineThread.isAlive()) {
  224.          this.engineThread.stop();
  225.       }
  226.  
  227.       this.engineThread = null;
  228.    }
  229.  
  230.    public void update(Graphics var1) {
  231.       if (this.readyToPaint) {
  232.          this.paint(var1);
  233.       }
  234.  
  235.    }
  236.  
  237.    public void run() {
  238.       while(true) {
  239.          if (this.unreg && this.matched) {
  240.             ((Applet)this).getAppletContext().showStatus("Unregistered version. Copyright (c) Sausage Software 1996");
  241.          }
  242.  
  243.          ((Component)this).repaint();
  244.  
  245.          try {
  246.             Thread.sleep((long)(this.sleepTime + 10));
  247.          } catch (Exception var1) {
  248.          }
  249.  
  250.          this.readyToPaint = false;
  251.          this.xyUpdate();
  252.          this.readyToPaint = true;
  253.       }
  254.    }
  255.  
  256.    public boolean handleEvent(Event var1) {
  257.       if (var1.id == 501) {
  258.          if (this.userPause) {
  259.             this.engineThread.resume();
  260.          } else {
  261.             this.engineThread.suspend();
  262.          }
  263.  
  264.          this.userPause = !this.userPause;
  265.       } else if (var1.id == 201) {
  266.          this.stop();
  267.          System.exit(0);
  268.       }
  269.  
  270.       return true;
  271.    }
  272.  
  273.    private boolean verifyUser(String var1) {
  274.       this.passkey = this.decryption(var1);
  275.       this.passkey += this.decryption(this.reguser);
  276.       String var2 = this.intoLetters(Long.toString((long)this.passkey));
  277.       this.matched = this.serialid.regionMatches(true, 0, var2, 0, var2.length());
  278.       return this.matched;
  279.    }
  280.  
  281.    private void NotRegistered() {
  282.       System.out.println("Applet not registered");
  283.       this.matched = false;
  284.    }
  285.  
  286.    private int decryption(String var1) {
  287.       int var2 = 0;
  288.       long var3 = 345L;
  289.       long var5 = 56L;
  290.       long var7 = 345L;
  291.       long var9 = 49L;
  292.  
  293.       for(int var11 = 0; var11 < var1.length(); ++var11) {
  294.          var2 += var1.charAt(var11);
  295.          var3 = (long)((double)(var5 * 23L) / (double)2.5F + (double)var7);
  296.          var9 = 34L / var7;
  297.          var5 = var3 + var5 + (long)var2;
  298.       }
  299.  
  300.       return var2;
  301.    }
  302.  
  303.    private String intoLetters(String var1) {
  304.       char[] var2 = new char[var1.length()];
  305.  
  306.       for(int var3 = 0; var3 < var1.length(); ++var3) {
  307.          var2[var3] = (char)(Character.digit(var1.charAt(var3), 10) + 65);
  308.       }
  309.  
  310.       return String.valueOf(var2);
  311.    }
  312.  
  313.    public String getFontName(String var1) {
  314.       if (var1 == null) {
  315.          return new String("Helvetica");
  316.       } else {
  317.          Object var2 = null;
  318.          String var3 = var1.toLowerCase();
  319.          String var4;
  320.          if (var3.equals("courier")) {
  321.             var4 = "Courier";
  322.          } else if (var3.equals("helvetica")) {
  323.             var4 = "Helvetica";
  324.          } else if (var3.equals("dialog")) {
  325.             var4 = "Dialog";
  326.          } else if (var3.equals("timesroman")) {
  327.             var4 = "TimesRoman";
  328.          } else if (var3.equals("times roman")) {
  329.             var4 = "TimesRoman";
  330.          } else if (var3.equals("symbol")) {
  331.             var4 = "Symbol";
  332.          } else if (var3.equals("dialoginput")) {
  333.             var4 = "DialogInput";
  334.          } else if (var3.equals("zapfdingbats")) {
  335.             var4 = "ZapfDingbats";
  336.          } else {
  337.             var4 = "Helvetica";
  338.          }
  339.  
  340.          return new String(var4);
  341.       }
  342.    }
  343.  
  344.    public int getFontStyle(String var1) {
  345.       if (var1 == null) {
  346.          return 0;
  347.       } else {
  348.          String var2 = var1.toLowerCase();
  349.          if ("italic".equals(var2)) {
  350.             return 2;
  351.          } else if ("bold".equals(var2)) {
  352.             return 1;
  353.          } else {
  354.             return !"bold+italic".equals(var2) && !"italic+bold".equals(var2) ? 0 : 3;
  355.          }
  356.       }
  357.    }
  358. }
  359.