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