home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / WIN95 / JASP1_1C.EXE / Jasper.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-04-27  |  3.8 KB  |  141 lines

  1. import java.applet.Applet;
  2. import java.awt.Container;
  3. import java.awt.Dimension;
  4. import java.awt.Event;
  5. import java.awt.Graphics;
  6. import java.awt.LayoutManager;
  7. import java.io.InputStream;
  8. import java.net.URL;
  9. import java.net.URLConnection;
  10.  
  11. public class Jasper extends Applet implements Runnable {
  12.    Spectrum spectrum;
  13.    Thread thread;
  14.  
  15.    public String getAppletInfo() {
  16.       return "Jasper V1.1 by Adam Davidson and Andrew Pollard";
  17.    }
  18.  
  19.    public String[][] getParameterInfo() {
  20.       String[][] var1 = new String[][]{{"snapshot", "filename", "name of SNA or Z80 snapshot to load"}, {"rom", "filename", "filename of ROM (default=spectrum.rom)"}, {"borderWidth", "integer", "width of spectrum border (default=20)"}, {"refreshRate", "integer", "refresh screen every 'X' interrupts (default=1)"}, {"sleepHack", "integer", "sleep per interrupt in ms, for old VMs (default=0)"}, {"showStats", "Yes/No", "show progress bar (default=Yes)"}};
  21.       return var1;
  22.    }
  23.  
  24.    public void init() {
  25.       ((Container)this).setLayout((LayoutManager)null);
  26.    }
  27.  
  28.    public void start() {
  29.       if (this.thread == null) {
  30.          this.thread = new Thread(this, "Jasper");
  31.          this.thread.start();
  32.       }
  33.  
  34.    }
  35.  
  36.    public void stop() {
  37.       if (this.thread != null) {
  38.          this.thread.stop();
  39.          this.thread = null;
  40.       }
  41.  
  42.    }
  43.  
  44.    public void readParameters() throws Exception {
  45.       String var1 = ((Applet)this).getParameter("rom");
  46.       if (var1 == null) {
  47.          var1 = "spectrum.rom";
  48.       }
  49.  
  50.       this.spectrum.setBorderWidth(this.getIntParameter("borderWidth", this.spectrum.borderWidth, 0, 100));
  51.       this.spectrum.refreshRate = this.getIntParameter("refreshRate", this.spectrum.refreshRate, 1, 100);
  52.       this.spectrum.sleepHack = this.getIntParameter("sleepHack", this.spectrum.sleepHack, 0, 100);
  53.       ((Applet)this).resize(this.preferredSize());
  54.       String var2 = ((Applet)this).getParameter("showStats");
  55.       if (var2 != null) {
  56.          if (var2.equals("Yes")) {
  57.             this.spectrum.showStats = true;
  58.          } else if (var2.equals("No")) {
  59.             this.spectrum.showStats = false;
  60.          }
  61.       }
  62.  
  63.       URL var3 = ((Applet)this).getDocumentBase();
  64.       this.spectrum.urlField.setText(var3.toString());
  65.       URL var4 = new URL(var3, var1);
  66.       this.spectrum.loadROM(var4.toString(), var4.openStream());
  67.       String var5 = ((Applet)this).getParameter("snapshot");
  68.       var5 = var5 == null ? ((Applet)this).getParameter("sna") : var5;
  69.       var5 = var5 == null ? ((Applet)this).getParameter("z80") : var5;
  70.       if (var5 != null) {
  71.          URL var6 = new URL(var3, var5);
  72.          URLConnection var7 = var6.openConnection();
  73.          InputStream var8 = var7.getInputStream();
  74.          this.spectrum.loadSnapshot(var6.toString(), var8, var7.getContentLength());
  75.          var8.close();
  76.       } else {
  77.          this.spectrum.reset();
  78.          this.spectrum.refreshWholeScreen();
  79.       }
  80.    }
  81.  
  82.    public void run() {
  83.       ((Applet)this).showStatus(this.getAppletInfo());
  84.       if (this.spectrum == null) {
  85.          try {
  86.             this.spectrum = new Spectrum(this);
  87.             this.readParameters();
  88.          } catch (Exception var2) {
  89.             ((Applet)this).showStatus("Caught IO Error: " + ((Throwable)var2).toString());
  90.          }
  91.       }
  92.  
  93.       if (this.spectrum != null) {
  94.          this.spectrum.execute();
  95.       }
  96.  
  97.    }
  98.  
  99.    public int getIntParameter(String var1, int var2, int var3, int var4) {
  100.       String var5 = ((Applet)this).getParameter(var1);
  101.       if (var5 == null) {
  102.          return var2;
  103.       } else {
  104.          try {
  105.             int var6 = Integer.parseInt(var5);
  106.             if (var6 < var3) {
  107.                return var3;
  108.             } else {
  109.                return var6 > var4 ? var4 : var6;
  110.             }
  111.          } catch (Exception var7) {
  112.             return var2;
  113.          }
  114.       }
  115.    }
  116.  
  117.    public void update(Graphics var1) {
  118.       this.paint(var1);
  119.    }
  120.  
  121.    public void paint(Graphics var1) {
  122.       if (this.spectrum != null) {
  123.          this.spectrum.repaint();
  124.       }
  125.  
  126.    }
  127.  
  128.    public boolean handleEvent(Event var1) {
  129.       return this.spectrum != null ? this.spectrum.handleEvent(var1) : super.handleEvent(var1);
  130.    }
  131.  
  132.    public Dimension minimumSize() {
  133.       int var1 = this.spectrum == null ? 20 : this.spectrum.borderWidth;
  134.       return new Dimension(256 + var1 * 2, 192 + var1 * 2);
  135.    }
  136.  
  137.    public Dimension preferredSize() {
  138.       return this.minimumSize();
  139.    }
  140. }
  141.