import java.applet.Applet; import java.awt.*; public class MultiThread extends Applet implements Runnable { Ball ball1, ball2, ball3; int w, h; Thread drawBall; boolean cont = true; public void init() { w = this.getWidth(); h = this.getHeight(); ball1 = new Ball(1, 2, w, h); ball1.start(); ball2 = new Ball(2, 1, w, h); ball2.start(); ball3 = new Ball(3, 2, w, h); ball3.start(); drawBall = new Thread(this); drawBall.start(); } public void run() { while (cont) { try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } repaint(); } } public void paint(Graphics g) { ball1.draw(g); ball2.draw(g); ball3.draw(g); } public void stop() { cont = false; ball1.tstop(); ball2.tstop(); ball3.tstop(); } }