home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / WIN95 / MSGSCROL.EXE / MsgScroll.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-09-02  |  5.6 KB  |  276 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.util.StringTokenizer;
  11.  
  12. public class MsgScroll extends Applet implements Runnable {
  13.    int delay = 25;
  14.    String msg = "Your message here...";
  15.    Color fgColor;
  16.    Color bgColor;
  17.    int shxOffset;
  18.    int shyOffset;
  19.    Color shColor;
  20.    int bdSize;
  21.    Color bdColor;
  22.    String fontName;
  23.    int fontStyle;
  24.    int fontSize;
  25.    Thread scrollThread;
  26.    boolean suspended;
  27.    Font font;
  28.    int msgWidth;
  29.    int xOffset;
  30.    int xOffsetMax;
  31.    int xOffsetMin;
  32.    int yOffset;
  33.    Dimension offDimension;
  34.    Image offImage;
  35.    Graphics offGraphics;
  36.  
  37.    public void init() {
  38.       try {
  39.          String var1 = ((Applet)this).getParameter("delay");
  40.          int var4;
  41.          if (var1 != null && (var4 = Integer.parseInt(var1)) > 0) {
  42.             this.delay = var4;
  43.          }
  44.       } catch (Exception var13) {
  45.       }
  46.  
  47.       try {
  48.          String var14 = ((Applet)this).getParameter("msg");
  49.          if (var14 != null) {
  50.             this.msg = var14;
  51.          }
  52.       } catch (Exception var12) {
  53.       }
  54.  
  55.       try {
  56.          String var15 = ((Applet)this).getParameter("fgcolor");
  57.          if (var15 != null) {
  58.             this.fgColor = this.getColorParm(var15);
  59.          }
  60.       } catch (Exception var11) {
  61.       }
  62.  
  63.       this.bdColor = this.fgColor;
  64.  
  65.       try {
  66.          String var16 = ((Applet)this).getParameter("bgcolor");
  67.          if (var16 != null) {
  68.             this.bgColor = this.getColorParm(var16);
  69.          }
  70.       } catch (Exception var10) {
  71.       }
  72.  
  73.       try {
  74.          String var17 = ((Applet)this).getParameter("shadow");
  75.          if (var17 != null) {
  76.             StringTokenizer var3 = new StringTokenizer(var17, ",");
  77.             int var24;
  78.             if ((var24 = Integer.parseInt(var3.nextToken())) > 0) {
  79.                this.shxOffset = var24;
  80.             }
  81.  
  82.             if ((var24 = Integer.parseInt(var3.nextToken())) > 0) {
  83.                this.shyOffset = var24;
  84.             }
  85.  
  86.             this.shColor = this.getColorParm(var3.nextToken());
  87.          }
  88.       } catch (Exception var9) {
  89.       }
  90.  
  91.       try {
  92.          String var18 = ((Applet)this).getParameter("border");
  93.          if (var18 != null) {
  94.             StringTokenizer var22 = new StringTokenizer(var18, ",");
  95.             int var26;
  96.             if ((var26 = Integer.parseInt(var22.nextToken())) > 0) {
  97.                this.bdSize = var26;
  98.             }
  99.  
  100.             this.bdColor = this.getColorParm(var22.nextToken());
  101.          }
  102.       } catch (Exception var8) {
  103.       }
  104.  
  105.       try {
  106.          String var19 = ((Applet)this).getParameter("font");
  107.          StringTokenizer var23 = new StringTokenizer(var19, ",");
  108.          String var2 = var23.nextToken();
  109.          if (var2.equalsIgnoreCase("Courier")) {
  110.             this.fontName = "Courier";
  111.          } else if (var2.equalsIgnoreCase("Dialog")) {
  112.             this.fontName = "Dialog";
  113.          } else if (var2.equalsIgnoreCase("Helvetica")) {
  114.             this.fontName = "Helvetica";
  115.          } else if (var2.equalsIgnoreCase("Symbol")) {
  116.             this.fontName = "Symbol";
  117.          } else if (var2.equalsIgnoreCase("TimesRoman")) {
  118.             this.fontName = "TimesRoman";
  119.          }
  120.  
  121.          var2 = var23.nextToken();
  122.          if (var2.equalsIgnoreCase("plain")) {
  123.             this.fontStyle = 0;
  124.          } else if (var2.equalsIgnoreCase("bold")) {
  125.             this.fontStyle = 1;
  126.          } else if (var2.equalsIgnoreCase("italic")) {
  127.             this.fontStyle = 2;
  128.          } else if (var2.equalsIgnoreCase("boldItalic")) {
  129.             this.fontStyle = 3;
  130.          }
  131.  
  132.          var2 = var23.nextToken();
  133.          int var27;
  134.          if ((var27 = Integer.parseInt(var2)) > 0) {
  135.             this.fontSize = var27;
  136.          }
  137.       } catch (Exception var7) {
  138.       }
  139.  
  140.       Graphics var5 = ((Component)this).getGraphics();
  141.       this.font = var5.getFont();
  142.       var5.setFont(this.font = new Font(this.fontName, this.fontStyle, this.fontSize));
  143.       FontMetrics var6 = var5.getFontMetrics();
  144.       this.msgWidth = var6.stringWidth(this.msg);
  145.       this.xOffsetMin = -this.msgWidth;
  146.       this.xOffsetMax = ((Component)this).size().width;
  147.       this.xOffset = this.xOffsetMax;
  148.       this.yOffset = ((Component)this).size().height - (((Component)this).size().height - var6.getHeight()) / 2 - var6.getDescent();
  149.    }
  150.  
  151.    private Color getColorParm(String var1) {
  152.       if (var1.equalsIgnoreCase("black")) {
  153.          return Color.black;
  154.       } else if (var1.equalsIgnoreCase("blue")) {
  155.          return Color.blue;
  156.       } else if (var1.equalsIgnoreCase("cyan")) {
  157.          return Color.cyan;
  158.       } else if (var1.equalsIgnoreCase("darkGray")) {
  159.          return Color.darkGray;
  160.       } else if (var1.equalsIgnoreCase("gray")) {
  161.          return Color.gray;
  162.       } else if (var1.equalsIgnoreCase("green")) {
  163.          return Color.green;
  164.       } else if (var1.equalsIgnoreCase("lightGray")) {
  165.          return Color.lightGray;
  166.       } else if (var1.equalsIgnoreCase("magenta")) {
  167.          return Color.magenta;
  168.       } else if (var1.equalsIgnoreCase("orange")) {
  169.          return Color.orange;
  170.       } else if (var1.equalsIgnoreCase("pink")) {
  171.          return Color.pink;
  172.       } else if (var1.equalsIgnoreCase("red")) {
  173.          return Color.red;
  174.       } else if (var1.equalsIgnoreCase("white")) {
  175.          return Color.white;
  176.       } else if (var1.equalsIgnoreCase("yellow")) {
  177.          return Color.yellow;
  178.       } else if (var1.length() == 7 && var1.charAt(0) == '#') {
  179.          int var2 = Integer.parseInt(var1.substring(1, 3), 16);
  180.          int var3 = Integer.parseInt(var1.substring(3, 5), 16);
  181.          int var4 = Integer.parseInt(var1.substring(5, 7), 16);
  182.          return new Color(var2, var3, var4);
  183.       } else {
  184.          return Color.black;
  185.       }
  186.    }
  187.  
  188.    public void start() {
  189.       if (this.scrollThread == null) {
  190.          this.scrollThread = new Thread(this);
  191.          this.scrollThread.start();
  192.       }
  193.  
  194.    }
  195.  
  196.    public void stop() {
  197.       if (this.scrollThread != null) {
  198.          this.scrollThread.stop();
  199.          this.scrollThread = null;
  200.       }
  201.  
  202.    }
  203.  
  204.    public boolean mouseDown(Event var1, int var2, int var3) {
  205.       if (this.suspended) {
  206.          this.start();
  207.       } else {
  208.          this.stop();
  209.       }
  210.  
  211.       this.suspended = !this.suspended;
  212.       return true;
  213.    }
  214.  
  215.    public void run() {
  216.       Thread.currentThread().setPriority(1);
  217.       long var1 = System.currentTimeMillis();
  218.  
  219.       while(Thread.currentThread() == this.scrollThread) {
  220.          if (--this.xOffset < this.xOffsetMin) {
  221.             this.xOffset = this.xOffsetMax;
  222.          }
  223.  
  224.          ((Component)this).repaint();
  225.  
  226.          try {
  227.             var1 += (long)this.delay;
  228.             Thread.sleep(Math.max(0L, var1 - System.currentTimeMillis()));
  229.          } catch (InterruptedException var3) {
  230.             return;
  231.          }
  232.       }
  233.  
  234.    }
  235.  
  236.    public void paint(Graphics var1) {
  237.       this.update(var1);
  238.    }
  239.  
  240.    public void update(Graphics var1) {
  241.       Dimension var2 = ((Component)this).size();
  242.       if (this.offGraphics == null || var2.width != this.offDimension.width || var2.height != this.offDimension.height) {
  243.          this.offDimension = var2;
  244.          this.offImage = ((Component)this).createImage(var2.width, var2.height);
  245.          this.offGraphics = this.offImage.getGraphics();
  246.       }
  247.  
  248.       this.offGraphics.setColor(this.bgColor);
  249.       this.offGraphics.fillRect(0, 0, var2.width, var2.height);
  250.       this.offGraphics.setFont(this.font);
  251.       if (this.shxOffset != 0 || this.shyOffset != 0) {
  252.          this.offGraphics.setColor(this.shColor);
  253.          this.offGraphics.drawString(this.msg, this.xOffset + this.shxOffset, this.yOffset + this.shyOffset);
  254.       }
  255.  
  256.       this.offGraphics.setColor(this.fgColor);
  257.       this.offGraphics.drawString(this.msg, this.xOffset, this.yOffset);
  258.       this.offGraphics.setColor(this.bdColor);
  259.  
  260.       for(int var3 = 0; var3 < this.bdSize; ++var3) {
  261.          this.offGraphics.drawRect(var3, var3, var2.width - 2 * var3 - 1, var2.height - 2 * var3 - 1);
  262.       }
  263.  
  264.       var1.drawImage(this.offImage, 0, 0, this);
  265.    }
  266.  
  267.    public MsgScroll() {
  268.       this.fgColor = Color.black;
  269.       this.bgColor = Color.white;
  270.       this.shColor = Color.lightGray;
  271.       this.fontName = "Dialog";
  272.       this.fontSize = 12;
  273.       this.suspended = false;
  274.    }
  275. }
  276.