import java.awt.*; import java.applet.AudioClip; public class LaughTrack extends javax.swing.JApplet implements Runnable { AudioClip[] laugh = new AudioClip[4]; Thread runner; public void start() { if (runner == null) { runner = new Thread(this); runner.start(); } } public void stop() { if (runner != null) { for (int i = 0; i < laugh.length; i++) if (laugh[i] != null) laugh[i].stop(); runner = null; } } public void init() { for (int i = 0; i < laugh.length; i++) laugh[i] = getAudioClip(getCodeBase(), "laugh" + i + ".wav"); } public void run() { for (int i = 0; i < laugh.length; i++) if (laugh[i] != null) laugh[i].loop(); Thread thisThread = Thread.currentThread(); while (runner == thisThread) { try { Thread.sleep(5000); } catch (InterruptedException e) { } } } public void paint(Graphics screen) { Graphics2D screen2D = (Graphics2D) screen; screen2D.drawString("Playing Sounds ...", 10, 50); } }