Threading an Applet
public class RenewApplet extends java.applet.Applet implements Runnable { Thread thread; boolean running; int renewInterval = 500; public void run() { while ( running ) { redoAction (); try { Thread.sleep( renewInterval ); } catch ( InterruptedException e) { System.out.println( "Interrupted..." ); return; } } } public void start() { if ( !running ) { running = true; thread = new Thread (this); thread.start(); } } public void stop() { thread.interrupt(); running = false; } }
No comments:
Post a Comment