home *** CD-ROM | disk | FTP | other *** search
/ Learn Java Now / Learn_Java_Now_Microsoft_1996.iso / MsDev / Samples / Sun / NervousText / nervoustext.java < prev    next >
Encoding:
Java Source  |  1996-07-23  |  1.6 KB  |  78 lines

  1. /*  Daniel Wyszynski 
  2.     Center for Applied Large-Scale Computing (CALC) 
  3.     04-12-95 
  4.  
  5.     Test of text animation.
  6.  
  7.     kwalrath: Changed string; added thread suspension. 5-9-95
  8. */
  9. import java.awt.Graphics;
  10. import java.awt.Font;
  11.  
  12. public class nervoustext extends java.applet.Applet implements Runnable {
  13.  
  14.     char separated[];
  15.     String s = null;
  16.     Thread killme = null;
  17.     int i;
  18.     int x_coord = 0, y_coord = 0;
  19.     String num;
  20.     int speed=35;
  21.     int counter =0;
  22.     boolean threadSuspended = false; //added by kwalrath
  23.  
  24. public void init() {
  25.     resize(150,50);
  26.     setFont(new Font("TimesRoman",Font.BOLD,36));
  27.     s = getParameter("text");
  28.     if (s == null) {
  29.         s = "HotJava";
  30.     }
  31.  
  32.     separated =  new char [s.length()];
  33.     s.getChars(0,s.length(),separated,0);
  34.  }
  35.  
  36. public void start() {
  37.     if(killme == null) 
  38.     {
  39.         killme = new Thread(this);
  40.         killme.start();
  41.     }
  42.  }
  43.  
  44. public void stop() {
  45.     killme = null;
  46.  }
  47.  
  48. public void run() {
  49.     while (killme != null) {
  50.     try {Thread.sleep(100);} catch (InterruptedException e){}
  51.     repaint();
  52.     }
  53.     killme = null;
  54.  }
  55.  
  56. public void paint(Graphics g) {
  57.     for(i=0;i<s.length();i++)
  58.     {
  59.     x_coord = (int) (Math.random()*10+15*i);
  60.     y_coord = (int) (Math.random()*10+36);
  61.     g.drawChars(separated, i,1,x_coord,y_coord);
  62.     }
  63.  }
  64.  
  65. /* Added by kwalrath. */
  66. public boolean mouseDown(java.awt.Event evt, int x, int y) {
  67.         if (threadSuspended) {
  68.             killme.resume();
  69.         }
  70.         else {
  71.             killme.suspend();
  72.         }
  73.         threadSuspended = !threadSuspended;
  74.     return true;
  75.     }
  76. }
  77.  
  78.