import java.awt.*; import java.awt.event.*; import java.applet.*; public class OvalApplet extends Applet { public static final int IDEAL_WIDTH = 400; public static final int IDEAL_HEIGHT = 400; public void paint(Graphics g) { g.setColor(Color.BLACK); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.WHITE); for (int i = 0; i < 100; i++) { int x = (int) (Math.random() * getWidth()); int y = (int) (Math.random() * getHeight()); int width = (int) (Math.random() * 50) + 5; int height = (int) (Math.random() * 50) + 5; int color = (int) (Math.random() * 5) + 1; switch (color) { case 1: g.setColor(Color.BLUE); break; case 2: g.setColor(Color.CYAN); break; case 3: g.setColor(Color.YELLOW); break; case 4: g.setColor(Color.GREEN); break; case 5: g.setColor(Color.RED); break; } g.fillOval(x, y, width, height); } } public static void main(String args[]) { Applet applet = new OvalApplet(); Frame frame = new Frame(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.add(applet); frame.setSize(IDEAL_WIDTH, IDEAL_HEIGHT); frame.show(); } }