// Written by: Darren Gates & Ray Klefstad // Date: January 2000 // School: U.C. Irvine import java.awt.*; import java.awt.event.*; import java.applet.*; public class ThreadsExample extends Applet { public TextField t, t1; public Panel p; public void init() { t = new TextField(10); t1 = new TextField(10); p = new Panel(); p.add(t); p.add(t1); add(p); new CountUp().start(); new CountDown().start(); } class CountDown extends Thread implements Runnable { public CountDown() { } public void run() { // try/catch block required to sleep try { for (int i = 1000000; i > 0; i--) { // pause for 500 milliseconds sleep((long)500); t1.setText(i + ""); } } catch(InterruptedException e) { } } } class CountUp extends Thread implements Runnable { public CountUp() { } public void run() { for (int i = 0; i < 1000000; i++) { t.setText(i + ""); } } } }