import java.awt.*; import java.applet.*; import java.util.Random; /** * This class displays lots of "Hello world!"s on the applet window. */ public class HelloWorld3 extends Applet { private static final Color[] colors = {Color.black,Color.red,Color.blue,Color.green,Color.yellow}; private static Random randy; private Dimension dim; private int numReps; private int RandomInRange(int low, int high) { return (Math.abs(randy.nextInt()) % (high-low+1)) + low; } public void init() { randy = new Random(); dim = getSize(); numReps = Integer.parseInt(getParameter("reps")); } public void paint(Graphics g) { for (int i = 0; i < numReps; i++) { int x = RandomInRange(1, dim.width-60); int y = RandomInRange(10, dim.height); g.setColor(colors[RandomInRange(0,4)]); g.drawString("Hello world!", x, y); } } }