import java.applet.*;
import java.awt.*;
public class PoetryApplet extends Applet {
private String[] poem = new String[101];
private int numLines;
public void init() {
String nextline;
for (numLines = 1; numLines < poem.length; numLines++) {
nextline = this.getParameter("Line" + numLines);
if (nextline == null) break;
poem[numLines] = nextline;
}
numLines--;
}
public void paint(Graphics g) {
int y = 15;
for (int i=1; i <= numLines; i++) {
g.drawString(poem[i], 5, y);
y += 15;
}
}
}
Here's the applet:
You might think it would be useful to be able to process an arbitrary list of parameters without knowing their names in advance, if nothing else so you could return an error message to the page designer. Unfortunately there's still no way to do it in Java 1.5. (I asked James Gosling for this way back Java 1.0a3 in 1995, and he thought it would be a good idea.) It may appear in future versions.