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