home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2003 January / maximum-cd-2003-01.iso / Software / Utilities / JPerk / jperk.exe / _SETUP.1 / RTLScroll.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-13  |  4.4 KB  |  177 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.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.Rectangle;
  11.  
  12. public class RTLScroll extends Applet implements Runnable {
  13.    boolean gSok;
  14.    int speed = 10;
  15.    int jump = 1;
  16.    int size = 14;
  17.    int advance;
  18.    String message = "Specify a message in the Applet parameters.";
  19.    Font font = new Font("Times", 1, 14);
  20.    // $FF: renamed from: x int
  21.    int field_0;
  22.    // $FF: renamed from: y int
  23.    int field_1;
  24.    Color textcolor = new Color(255);
  25.    Color bgcolor = new Color(16777215);
  26.    Image offscreen;
  27.    int imagewidth;
  28.    int imageheight;
  29.    int stringwidth;
  30.    int stringheight;
  31.    int stringascent;
  32.    Thread animator;
  33.    boolean please_stop;
  34.  
  35.    public void start() {
  36.       this.animator = new Thread(this);
  37.       this.animator.start();
  38.    }
  39.  
  40.    public void stop() {
  41.       if (this.animator != null) {
  42.          this.animator.stop();
  43.       }
  44.  
  45.       this.animator = null;
  46.    }
  47.  
  48.    public boolean mouseDown(Event e, int x, int y) {
  49.       if (this.animator != null) {
  50.          this.please_stop = true;
  51.       } else {
  52.          this.please_stop = false;
  53.          this.start();
  54.       }
  55.  
  56.       return true;
  57.    }
  58.  
  59.    public void drawBackground(Graphics gr, Color c) {
  60.       Dimension size = ((Component)this).size();
  61.       int w = size.width;
  62.       int h = size.height;
  63.       gr.setColor(this.bgcolor);
  64.       gr.fillRect(0, 0, w, h);
  65.    }
  66.  
  67.    public void run() {
  68.       while(!this.please_stop) {
  69.          Dimension d = ((Component)this).size();
  70.          if (this.offscreen == null || this.imagewidth != d.width || this.imageheight != d.height) {
  71.             this.offscreen = ((Component)this).createImage(d.width, d.height);
  72.             this.imagewidth = d.width;
  73.             this.imageheight = d.height;
  74.          }
  75.  
  76.          if (this.field_0 <= -this.stringwidth) {
  77.             this.field_0 = d.width;
  78.             ((Component)this).repaint();
  79.          }
  80.  
  81.          Rectangle oldrect = new Rectangle(this.field_0, this.field_1 - this.stringascent, this.stringwidth, this.stringheight);
  82.          this.field_0 = (this.field_0 - this.jump) % d.width;
  83.          Rectangle newrect = new Rectangle(this.field_0, this.field_1 - this.stringascent, this.stringwidth, this.stringheight);
  84.          Rectangle r = newrect.union(oldrect);
  85.          Graphics g = this.offscreen.getGraphics();
  86.          g.clipRect(r.x, r.y, r.width, r.height);
  87.          this.paint(g);
  88.          g = ((Component)this).getGraphics();
  89.          g.clipRect(r.x, r.y, r.width, r.height);
  90.          g.drawImage(this.offscreen, 0, 0, this);
  91.  
  92.          try {
  93.             Thread.sleep((long)this.speed);
  94.          } catch (InterruptedException var8) {
  95.          }
  96.       }
  97.  
  98.       this.animator = null;
  99.    }
  100.  
  101.    public void init() {
  102.       Dimension d = ((Component)this).size();
  103.       String crstr = "Copyright (c) 1997 OpenCube Technologies";
  104.       String paramStr = ((Applet)this).getParameter("Notice");
  105.       if (paramStr != null) {
  106.          if (paramStr.equals(crstr)) {
  107.             this.gSok = true;
  108.          } else {
  109.             this.gSok = false;
  110.          }
  111.       } else {
  112.          this.gSok = false;
  113.       }
  114.  
  115.       paramStr = ((Applet)this).getParameter("jump");
  116.       if (paramStr != null) {
  117.          this.jump = Integer.parseInt(paramStr);
  118.       }
  119.  
  120.       paramStr = ((Applet)this).getParameter("message");
  121.       if (paramStr != null) {
  122.          this.message = paramStr;
  123.       }
  124.  
  125.       paramStr = ((Applet)this).getParameter("size");
  126.       if (paramStr != null) {
  127.          this.size = Integer.parseInt(paramStr);
  128.       }
  129.  
  130.       paramStr = ((Applet)this).getParameter("font");
  131.       if (paramStr != null) {
  132.          this.font = new Font(paramStr, 1, this.size);
  133.       }
  134.  
  135.       paramStr = ((Applet)this).getParameter("textcolor");
  136.       if (paramStr != null) {
  137.          this.textcolor = new Color(Integer.parseInt(paramStr));
  138.       }
  139.  
  140.       paramStr = ((Applet)this).getParameter("bgcolor");
  141.       if (paramStr != null) {
  142.          this.bgcolor = new Color(Integer.parseInt(paramStr));
  143.       }
  144.  
  145.       paramStr = ((Applet)this).getParameter("speed");
  146.       if (paramStr != null) {
  147.          this.speed = Integer.parseInt(paramStr);
  148.       }
  149.  
  150.       if (this.gSok) {
  151.          FontMetrics fm = ((Component)this).getFontMetrics(this.font);
  152.          this.stringwidth = fm.stringWidth(this.message);
  153.          this.stringheight = fm.getHeight();
  154.          this.stringascent = fm.getAscent();
  155.          this.advance = fm.getMaxAdvance();
  156.          this.field_1 = (d.height + this.stringascent) / 2;
  157.          this.field_0 = d.width;
  158.          ((Component)this).setBackground(this.bgcolor);
  159.       } else {
  160.          try {
  161.             Thread.sleep(1000L);
  162.          } catch (InterruptedException var6) {
  163.          }
  164.  
  165.          System.exit(0);
  166.       }
  167.  
  168.    }
  169.  
  170.    public void paint(Graphics g) {
  171.       this.drawBackground(g, this.bgcolor);
  172.       g.setColor(this.textcolor);
  173.       g.setFont(this.font);
  174.       g.drawString(this.message, this.field_0, this.field_1);
  175.    }
  176. }
  177.