FileDocCategorySizeDatePackage
Bounce.javaAPI DocExample1419Sun Mar 07 19:38:16 GMT 2004None

Bounce

public class Bounce extends Applet implements ActionListener
This is the Bounce class; create and start Sprites, using Threads.

Fields Summary
protected Panel
p
The main Panel
protected Image
img
The image, shared by all the Sprite objects
protected Vector
v
A Vector of Sprite objects.
Constructors Summary
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

		System.out.println("Creat-ing another one!");
		Sprite s = new Sprite(this, img);
		s.start();
		p.add(s);
		v.addElement(s);
    
public voidinit()

		Button b = new Button("Start");
		b.addActionListener(this);
		setLayout(new BorderLayout());
		add(b, BorderLayout.NORTH);
		add(p = new Panel(), BorderLayout.CENTER);
		p.setLayout(null);
		String imgName = getParameter("imagefile");
		if (imgName == null) imgName = "duke.gif";
		img = getImage(getCodeBase(), imgName);
		MediaTracker mt = new MediaTracker(this);
		mt.addImage(img, 0);
		try {
			mt.waitForID(0);
		} catch(InterruptedException e) {
			throw new IllegalArgumentException(
				"InterruptedException while loading image " + imgName);
		}
		if (mt.isErrorID(0)) {
			throw new IllegalArgumentException(
				"Couldn't load image " + imgName);
		}
		v = new Vector();
    
public voidstop()

		for (int i=0; i<v.size(); i++) {
			((Sprite)(v.get(i))).stop();
		}
		v.clear();