import java.awt.*; import java.awt.event.*; import java.lang.Thread; import java.net.*; public class prob6 extends java.applet.Applet implements Runnable { Image ball,squish; int loc; Thread t; public void start() { try { ball = getImage(new URL(getCodeBase()+"ball1.gif")); squish = getImage(new URL(getCodeBase()+"ball2.gif")); MediaTracker mt = new MediaTracker(this); mt.addImage(ball, 0); mt.addImage(squish, 0); mt.waitForAll(); } catch(Exception e) { System.err.println("Exception "+e);return; } t = new Thread(this); t.start(); super.start(); } public void stop() { t.stop(); super.stop(); } public void run() { while(true) { for(loc = 0; loc <= 435; loc+=5) { repaint(); t.yield(); } for(;loc >= 5; loc-=5) { repaint(); t.yield(); } } } public void paint(Graphics g) { g.drawImage((loc>425 ? squish : ball), 50, loc, this); super.paint(g); } }