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

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Choice;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.Event;
  8. import java.awt.FlowLayout;
  9. import java.awt.Frame;
  10. import java.awt.Graphics;
  11. import java.awt.Image;
  12. import java.awt.Label;
  13. import java.awt.MediaTracker;
  14. import java.awt.Panel;
  15. import java.net.MalformedURLException;
  16. import java.net.URL;
  17. import java.util.Vector;
  18.  
  19. public class buttmult extends Applet implements Runnable {
  20.    private Thread buttmultThread;
  21.    private boolean onButt;
  22.    private boolean pressedButt;
  23.    private boolean onIs;
  24.    private Image buttonup;
  25.    private Image buttondown;
  26.    private MediaTracker tracker;
  27.    // $FF: renamed from: i1 java.lang.String
  28.    private String field_0;
  29.    // $FF: renamed from: i2 java.lang.String
  30.    private String field_1;
  31.    private String destination;
  32.    private String music;
  33.    private String stringbutton;
  34.    private String label;
  35.    private URL imageSourceURL;
  36.    private URL soundSourceURL;
  37.    private AudioClip buttonsound;
  38.    private boolean loaded;
  39.    private String urlbutton = "CLICK HERE";
  40.    private int labelmax = 80;
  41.    private String reguser;
  42.    private String serialid;
  43.    private int passkey;
  44.    private String passkey_string;
  45.    private String keyvalue;
  46.    private Frame destFrame;
  47.    private Panel myPanel;
  48.    private Choice comboBox;
  49.    private String sausage = "http://www.sausage.com";
  50.    Dimension dim;
  51.    private Vector urlVectors;
  52.    private boolean bNotRegistered;
  53.    private boolean imageError;
  54.  
  55.    public void stop() {
  56.       if (this.buttmultThread != null && this.buttmultThread.isAlive()) {
  57.          this.buttmultThread.stop();
  58.       }
  59.  
  60.       try {
  61.          this.destFrame.hide();
  62.          this.destFrame.dispose();
  63.       } catch (Exception var1) {
  64.       }
  65.  
  66.       this.buttmultThread = null;
  67.    }
  68.  
  69.    void clearMessage() {
  70.       ((Applet)this).showStatus("");
  71.    }
  72.  
  73.    private void NotRegistered() {
  74.       System.out.println("Program not registered");
  75.       this.bNotRegistered = true;
  76.    }
  77.  
  78.    private void playSound() {
  79.       if (this.buttonsound != null) {
  80.          this.buttonsound.play();
  81.       }
  82.  
  83.    }
  84.  
  85.    private String intoLetters(String var1) {
  86.       char[] var2 = new char[var1.length()];
  87.  
  88.       for(int var3 = 0; var3 < var1.length(); ++var3) {
  89.          var2[var3] = (char)(Character.digit(var1.charAt(var3), 10) + 65);
  90.       }
  91.  
  92.       return String.valueOf(var2);
  93.    }
  94.  
  95.    public void paint(Graphics var1) {
  96.       if (this.loaded && !this.bNotRegistered) {
  97.          if (this.tracker.isErrorAny()) {
  98.             var1.setColor(Color.red);
  99.             var1.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  100.             var1.setColor(Color.black);
  101.             var1.drawString("Error Loading Images", 2, 20);
  102.             return;
  103.          }
  104.  
  105.          if (this.onIs) {
  106.             var1.drawImage(this.buttondown, 0, 0, this);
  107.          } else {
  108.             var1.drawImage(this.buttonup, 0, 0, this);
  109.          }
  110.       }
  111.  
  112.    }
  113.  
  114.    private void dbg(String var1) {
  115.    }
  116.  
  117.    public void WindowFrame() {
  118.       this.destFrame = new proframe(this.label, this);
  119.       this.destFrame.setLayout(new FlowLayout());
  120.       this.myPanel = new Panel();
  121.       this.myPanel.add(new Label(this.label));
  122.       this.myPanel.add(this.comboBox = new Choice());
  123.       if (this.destination != null) {
  124.          this.urlVectors = this.parseVectors(this.destination);
  125.          int var1 = this.urlVectors.size();
  126.  
  127.          for(int var2 = 0; var2 < var1; ++var2) {
  128.             Object var3 = this.urlVectors.elementAt(var2);
  129.             this.comboBox.addItem((String)var3);
  130.          }
  131.       } else {
  132.          this.comboBox.addItem(this.sausage);
  133.          this.urlVectors = new Vector();
  134.          this.urlVectors.addElement(this.sausage);
  135.       }
  136.  
  137.       this.destFrame.add("North", this.myPanel);
  138.       this.dim = this.destFrame.preferredSize();
  139.       System.out.println("Try " + this.dim.toString());
  140.       this.destFrame.resize(this.dim.width + 20, this.dim.height);
  141.       this.destFrame.pack();
  142.    }
  143.  
  144.    public void update(Graphics var1) {
  145.       if (this.onButt && this.pressedButt) {
  146.          this.onIs = true;
  147.       } else {
  148.          this.onIs = false;
  149.       }
  150.  
  151.       this.paint(var1);
  152.    }
  153.  
  154.    private synchronized boolean activate() {
  155.       this.dbg("clickedDown");
  156.       if (this.destFrame != null) {
  157.          this.destFrame.hide();
  158.          this.destFrame.show();
  159.          this.destFrame.toFront();
  160.          this.destFrame.resize(this.destFrame.preferredSize().width, 100);
  161.       }
  162.  
  163.       return true;
  164.    }
  165.  
  166.    private Vector parseVectors(String var1) {
  167.       Vector var2 = new Vector(20);
  168.  
  169.       int var4;
  170.       for(int var3 = 0; var3 < var1.length(); var3 = var4 + 1) {
  171.          var4 = var1.indexOf(44, var3);
  172.          if (var4 == -1) {
  173.             var4 = var1.length();
  174.          }
  175.  
  176.          String var5 = var1.substring(var3, var4);
  177.          var5 = var5.replace('\r', ' ');
  178.          var5 = var5.trim();
  179.          var2.addElement(var5);
  180.       }
  181.  
  182.       return var2;
  183.    }
  184.  
  185.    public void start() {
  186.       if (this.buttmultThread == null) {
  187.          this.buttmultThread = new Thread(this);
  188.       }
  189.  
  190.       this.buttmultThread.start();
  191.    }
  192.  
  193.    public String getAppletInfo() {
  194.       return "Clikette - buttmult.class v1.3 Copyright (c) Sausage Software 1996";
  195.    }
  196.  
  197.    private int decryption(String var1) {
  198.       int var2 = 0;
  199.  
  200.       for(int var3 = 0; var3 < var1.length(); ++var3) {
  201.          var2 += var1.charAt(var3);
  202.       }
  203.  
  204.       return var2;
  205.    }
  206.  
  207.    public void run() {
  208.       this.dbg("RUN");
  209.       this.keyvalue = new String(this.field_0);
  210.       this.keyvalue = this.keyvalue.concat(this.field_1);
  211.       this.keyvalue = this.keyvalue.concat(this.destination);
  212.       this.passkey = this.decryption(this.keyvalue);
  213.       this.passkey += this.decryption(this.reguser);
  214.       this.passkey_string = this.intoLetters(Integer.toString(this.passkey));
  215.       boolean var1 = this.serialid.regionMatches(true, 0, this.passkey_string, 0, this.passkey_string.length());
  216.       if (!var1) {
  217.          this.NotRegistered();
  218.       }
  219.  
  220.       if (this.bNotRegistered) {
  221.          while(true) {
  222.             ((Applet)this).showStatus("Registration Error, please run Clikette again");
  223.  
  224.             try {
  225.                Thread.sleep(20L);
  226.             } catch (InterruptedException var2) {
  227.             }
  228.          }
  229.       }
  230.  
  231.       if (this.imageError) {
  232.          while(true) {
  233.             ((Applet)this).showStatus("Image Error");
  234.  
  235.             try {
  236.                Thread.sleep(20L);
  237.             } catch (InterruptedException var3) {
  238.             }
  239.          }
  240.       }
  241.  
  242.       if (this.field_0 == null || this.field_1 == null) {
  243.          this.dbg("loaded true");
  244.  
  245.          while(true) {
  246.             ((Applet)this).showStatus("Error no images found");
  247.  
  248.             try {
  249.                Thread.sleep(20L);
  250.             } catch (InterruptedException var5) {
  251.             }
  252.          }
  253.       }
  254.  
  255.       try {
  256.          this.tracker.waitForID(0);
  257.          this.tracker.waitForID(1);
  258.       } catch (InterruptedException var4) {
  259.          return;
  260.       }
  261.  
  262.       this.WindowFrame();
  263.       this.loaded = true;
  264.       ((Component)this).repaint();
  265.       this.clearMessage();
  266.    }
  267.  
  268.    public void init() {
  269.       System.out.println(this.getAppletInfo());
  270.       String var1 = ((Applet)this).getParameter("imagesource");
  271.       if (var1 == null) {
  272.          this.imageSourceURL = ((Applet)this).getDocumentBase();
  273.       } else {
  274.          try {
  275.             this.imageSourceURL = new URL(((Applet)this).getDocumentBase(), var1 + "/");
  276.          } catch (MalformedURLException var3) {
  277.          }
  278.       }
  279.  
  280.       var1 = ((Applet)this).getParameter("sound");
  281.       if (var1 != null) {
  282.          this.soundSourceURL = ((Applet)this).getDocumentBase();
  283.          this.buttonsound = ((Applet)this).getAudioClip(this.soundSourceURL, var1);
  284.       } else {
  285.          this.buttonsound = null;
  286.       }
  287.  
  288.       this.tracker = new MediaTracker(this);
  289.  
  290.       try {
  291.          this.field_0 = ((Applet)this).getParameter("buttonup");
  292.          this.field_1 = ((Applet)this).getParameter("buttondown");
  293.          ((Applet)this).showStatus("Loading " + this.field_0);
  294.          this.buttonup = ((Applet)this).getImage(this.imageSourceURL, this.field_0);
  295.          this.tracker.addImage(this.buttonup, 0);
  296.          ((Applet)this).showStatus("Loading " + this.field_1);
  297.          this.buttondown = ((Applet)this).getImage(this.imageSourceURL, this.field_1);
  298.          this.tracker.addImage(this.buttondown, 1);
  299.       } catch (Exception var2) {
  300.          this.imageError = true;
  301.       }
  302.  
  303.       var1 = ((Applet)this).getParameter("stringbutton");
  304.       this.stringbutton = var1 != null ? var1 : "CLICK HERE";
  305.       var1 = ((Applet)this).getParameter("destination");
  306.       this.destination = var1 != null ? var1 : "http://www.sausage.com.au, http://www.sausage.com";
  307.       var1 = ((Applet)this).getParameter("label");
  308.       this.label = var1 == null ? "Pick Destination" : var1;
  309.       var1 = ((Applet)this).getParameter("reguser");
  310.       if (var1 == null) {
  311.          this.NotRegistered();
  312.       } else {
  313.          this.reguser = var1;
  314.       }
  315.  
  316.       var1 = ((Applet)this).getParameter("serialid");
  317.       if (var1 == null) {
  318.          this.NotRegistered();
  319.       } else {
  320.          this.serialid = var1;
  321.       }
  322.  
  323.       var1 = ((Applet)this).getParameter("labelmax");
  324.       this.labelmax = var1 == null ? 80 : Integer.parseInt(var1);
  325.    }
  326.  
  327.    public boolean handleEvent(Event var1) {
  328.       switch (var1.id) {
  329.          case 501:
  330.             if (!(var1.target instanceof Choice)) {
  331.                this.playSound();
  332.                this.pressedButt = true;
  333.                ((Component)this).repaint();
  334.             }
  335.             break;
  336.          case 502:
  337.             if (!(var1.target instanceof Choice)) {
  338.                if (this.pressedButt && this.onButt) {
  339.                   this.pressedButt = false;
  340.                   ((Component)this).repaint();
  341.                   this.activate();
  342.                } else {
  343.                   this.pressedButt = false;
  344.                }
  345.             }
  346.             break;
  347.          case 504:
  348.             this.onButt = true;
  349.             break;
  350.          case 505:
  351.             this.onButt = false;
  352.             break;
  353.          case 1001:
  354.             if (var1.target instanceof Choice) {
  355.                String var2 = (String)this.urlVectors.elementAt(this.comboBox.getSelectedIndex());
  356.                if (var2 != null && !var2.equals("#")) {
  357.                   URL var3 = null;
  358.  
  359.                   try {
  360.                      if (!this.bNotRegistered) {
  361.                         var3 = new URL(((Applet)this).getDocumentBase(), var2);
  362.                      }
  363.                   } catch (MalformedURLException var5) {
  364.                      ((Applet)this).showStatus("Please check your URL");
  365.                   }
  366.  
  367.                   if (var3 != null) {
  368.                      ((Applet)this).showStatus("Trying " + var2);
  369.  
  370.                      try {
  371.                         this.destFrame.hide();
  372.                         this.destFrame.dispose();
  373.                         ((Applet)this).getAppletContext().showDocument(var3, "_blank");
  374.                      } catch (Exception var4) {
  375.                         ((Applet)this).showStatus("ERROR loading" + var3);
  376.                      }
  377.                   } else {
  378.                      ((Applet)this).showStatus("Error in destination variable");
  379.                   }
  380.                }
  381.             }
  382.       }
  383.  
  384.       return true;
  385.    }
  386. }
  387.