Initialize the applet
// Turn off layout so the Sprite can move at will.
setLayout(null);
String imgName = getParameter("imagefile");
if (imgName == null)
throw new IllegalArgumentException(
"imagefile parameter required");
String orientation = getParameter("orientation");
if (orientation == null)
throw new IllegalArgumentException(
"orientation parameter required");
int orient = 0;
if (orientation.equalsIgnoreCase("horizontal"))
orient = Sprite.HORIZONTAL;
else if (orientation.equalsIgnoreCase("vertical"))
orient = Sprite.VERTICAL;
else
orient = Sprite.DIAGONAL;
// Create the Image
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);
}
s = new Sprite(this, img, orient);
add(s);
// Now see if the sleeptime was specified */
String sleep = getParameter("sleeptime");
if (sleep != null) {
try {
int n = Integer.parseInt(sleep);
s.setSleepTime(n);
} catch(IllegalArgumentException ex) {
showStatus("Invalid sleep time number in " + sleep);
}
}