<html><head><title> Test Applet </title></head><body><b>Beispiel TestApplet!</b><p><applet code = "TestApplet.class" width = 600 height = 400><param name = "p1" value = "0">Oops! Geht mit diesem Browser nicht!</applet></p><p><b>Hier gehts dann weiter</b></p></body></html>
import javax.swing.*;public class AppletThreadTestextends JAppletimplements Runnable{ public String p1; private String str; private int i; private int cnt = 0; private Thread thread1; private Thread thread2; public void init() { str = getParameter("p1"); i = Integer.parseInt(str); } public void stop() { if (thread1 != null) thread1 = null; if (thread2 != null) thread2 = null; } public void destroy() { } public void start() { thread1 = new Thread(this); thread1.start(); thread2 = new Thread(this); thread2.start(); } public void run() { Thread activeThread = Thread.currentThread(); while(thread1 == activeThread) { try { thread1.sleep(1); } catch (InterruptedException ie){ System.out.println("thread1 abgebrochen!"); } if (i < 100) { System.out.println("t1: " + ++cnt + " " + i++); } else break; } while(thread2 == activeThread) { try { thread2.sleep(1); } catch (InterruptedException ie){ System.out.println("thread1 abgebrochen!"); } if (i >= 0 && i < 100) { System.out.println("t2: " + ++cnt + " " + i--); } else break; } }}