home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap31 / ThreadApplet.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-03-21  |  1.3 KB  |  43 lines

  1. import java.applet.Applet;
  2. import java.awt.Component;
  3. import java.awt.Font;
  4. import java.awt.Graphics;
  5.  
  6. public class ThreadApplet extends Applet implements Runnable {
  7.    Thread thread;
  8.    int count;
  9.    String displayStr;
  10.    Font font;
  11.  
  12.    public void start() {
  13.       this.font = new Font("TimesRoman", 0, 72);
  14.       ((Component)this).setFont(this.font);
  15.       this.count = 0;
  16.       this.displayStr = "";
  17.       this.thread = new Thread(this);
  18.       this.thread.start();
  19.    }
  20.  
  21.    public void stop() {
  22.       this.thread.stop();
  23.    }
  24.  
  25.    public void run() {
  26.       while(this.count < 1000) {
  27.          ++this.count;
  28.          this.displayStr = String.valueOf(this.count);
  29.          ((Component)this).repaint();
  30.  
  31.          try {
  32.             Thread.sleep(100L);
  33.          } catch (InterruptedException var1) {
  34.          }
  35.       }
  36.  
  37.    }
  38.  
  39.    public void paint(Graphics var1) {
  40.       var1.drawString(this.displayStr, 50, 130);
  41.    }
  42. }
  43.