import java.awt.*; import java.applet.*; public class FlyingTiger1 extends Applet { int x, y, dx = 5, dy = 5; Image img = null; int imw = -1, imh = -1; public void init() { setBackground(Color.black); img = getImage(getCodeBase(), "tiger.gif"); MediaTracker mt = new MediaTracker(this); mt.addImage(img, 0); try { mt.waitForID(0); } catch (InterruptedException ie) { } x = getSize().width / 2; y = getSize().height / 2; } public void paint(Graphics g) { int w = getSize().width; int h = getSize().height; if (imw < 0) { imw = img.getWidth(this); imh = img.getHeight(this); } // Animate the image x += dx; y += dy; if (x + imw > w || x < 0 ) dx = - dx; if (y + imh > h || y < 0 ) dy = - dy; g.drawImage(img, x, y, this); repaint(50); } }