home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap31 / ThreadApplet3.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-03-21  |  1.4 KB  |  56 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 ThreadApplet3 extends Applet {
  7.    MyThread2 thread1;
  8.    MyThread2 thread2;
  9.    String displayStr;
  10.    Font font;
  11.    int position;
  12.  
  13.    public void init() {
  14.       this.font = new Font("TimesRoman", 0, 72);
  15.       ((Component)this).setFont(this.font);
  16.       this.displayStr = "";
  17.       this.position = 120;
  18.       this.thread1 = new MyThread2(this, true);
  19.       this.thread2 = new MyThread2(this, false);
  20.    }
  21.  
  22.    public void start() {
  23.       if (this.thread1.isAlive()) {
  24.          this.thread1.resume();
  25.       } else {
  26.          this.thread1.start();
  27.       }
  28.  
  29.       if (this.thread2.isAlive()) {
  30.          this.thread2.resume();
  31.       } else {
  32.          this.thread2.start();
  33.       }
  34.    }
  35.  
  36.    public void stop() {
  37.       this.thread1.suspend();
  38.       this.thread2.suspend();
  39.    }
  40.  
  41.    public void destroy() {
  42.       this.thread1.stop();
  43.       this.thread2.stop();
  44.    }
  45.  
  46.    public void paint(Graphics var1) {
  47.       var1.drawString(this.displayStr, 50, this.position);
  48.    }
  49.  
  50.    public synchronized void SetDisplayStr(String var1, int var2) {
  51.       this.displayStr = var1;
  52.       this.position = var2;
  53.       ((Component)this).repaint();
  54.    }
  55. }
  56.