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

  1. public class MyThread2 extends Thread {
  2.    ThreadApplet3 applet;
  3.    boolean forward;
  4.    int count;
  5.    int increment;
  6.    int end;
  7.    int position;
  8.  
  9.    MyThread2(ThreadApplet3 var1, boolean var2) {
  10.       this.applet = var1;
  11.       this.forward = var2;
  12.    }
  13.  
  14.    public void run() {
  15.       this.InitCounter();
  16.       this.DoCount();
  17.    }
  18.  
  19.    protected void InitCounter() {
  20.       if (this.forward) {
  21.          this.count = 0;
  22.          this.increment = 1;
  23.          this.end = 1000;
  24.          this.position = 120;
  25.       } else {
  26.          this.count = 1000;
  27.          this.increment = -1;
  28.          this.end = 0;
  29.          this.position = 180;
  30.       }
  31.    }
  32.  
  33.    protected void DoCount() {
  34.       while(this.count != this.end) {
  35.          this.count += this.increment;
  36.          String var1 = String.valueOf(this.count);
  37.          this.applet.SetDisplayStr(var1, this.position);
  38.  
  39.          try {
  40.             Thread.sleep(100L);
  41.          } catch (InterruptedException var2) {
  42.          }
  43.       }
  44.  
  45.    }
  46. }
  47.