home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 July & August / Pcwk78a98.iso / Internet / Javadraw / DATA.Z / NervousText.java < prev    next >
Text File  |  1997-04-01  |  3KB  |  120 lines

  1. /*
  2.  * @(#)NervousText.java    1.1 97/04/01
  3.  *
  4.  * Copyright (c) 1994-1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  7.  * modify and redistribute this software in source and binary code form,
  8.  * provided that i) this copyright notice and license appear on all copies of
  9.  * the software; and ii) Licensee does not utilize the software in a manner
  10.  * which is disparaging to Sun.
  11.  *
  12.  * This software is provided "AS IS," without a warranty of any kind. ALL
  13.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  14.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  15.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  16.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  17.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  18.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  19.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  20.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  21.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  22.  * POSSIBILITY OF SUCH DAMAGES.
  23.  *
  24.  * This software is not designed or intended for use in on-line control of
  25.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  26.  * the design, construction, operation or maintenance of any nuclear
  27.  * facility. Licensee represents and warrants that it will not use or
  28.  * redistribute the Software for such purposes.
  29.  */
  30.  
  31. /*  Daniel Wyszynski 
  32.     Center for Applied Large-Scale Computing (CALC) 
  33.     04-12-95 
  34.  
  35.     Test of text animation.
  36.  
  37.     kwalrath: Changed string; added thread suspension. 5-9-95
  38. */
  39. import java.awt.event.*;
  40. import java.awt.Graphics;
  41. import java.awt.Font;
  42.  
  43. public class NervousText extends java.applet.Applet implements Runnable, MouseListener {
  44.  
  45.     char separated[];
  46.     String s = null;
  47.     Thread killme = null;
  48.     int i;
  49.     int x_coord = 0, y_coord = 0;
  50.     String num;
  51.     int speed=35;
  52.     int counter =0;
  53.     boolean threadSuspended = false; //added by kwalrath
  54.  
  55. public void init() {
  56.     addMouseListener(this);
  57.     s = getParameter("text");
  58.     if (s == null) {
  59.         s = "HotJava";
  60.     }
  61.  
  62.     separated =  new char [s.length()];
  63.     s.getChars(0,s.length(),separated,0);
  64.     resize((s.length()+1)*15, 50);
  65.     setFont(new Font("TimesRoman",Font.BOLD,36));
  66.  }
  67.  
  68. public void start() {
  69.     if(killme == null) 
  70.     {
  71.         killme = new Thread(this);
  72.         killme.start();
  73.     }
  74.  }
  75.  
  76. public void stop() {
  77.     killme = null;
  78.  }
  79.  
  80. public void run() {
  81.     while (killme != null) {
  82.     try {Thread.sleep(100);} catch (InterruptedException e){}
  83.     repaint();
  84.     }
  85.     killme = null;
  86.  }
  87.  
  88. public void paint(Graphics g) {
  89.     for(i=0;i<s.length();i++)
  90.     {
  91.     x_coord = (int) (Math.random()*10+15*i);
  92.     y_coord = (int) (Math.random()*10+36);
  93.     g.drawChars(separated, i,1,x_coord,y_coord);
  94.     }
  95.  }
  96.  
  97.   public void mousePressed(MouseEvent e) {
  98.     e.consume();
  99.     if (threadSuspended) {
  100.       killme.resume();
  101.     }
  102.     else {
  103.       killme.suspend();
  104.     }
  105.     threadSuspended = !threadSuspended;
  106.   }
  107.  
  108.   public void mouseReleased(MouseEvent e) {
  109.   }
  110.  
  111.   public void mouseEntered(MouseEvent e) {
  112.   }
  113.  
  114.   public void mouseExited(MouseEvent e) {
  115.   }
  116.  
  117.   public void mouseClicked(MouseEvent e) {
  118.   }
  119. }
  120.