import java.awt.*; import java.applet.*; public class Stars extends Applet { private static final long serialVersionUID = 1L; public void paint(Graphics g) { g.fillRect(0, 0, getSize().width, getSize().height); //make background black for (long i = 1; i < 10000; i++) //generate 100000 stars { for (double j = 1; j < 1000000; j++); //slow down the computer int x = (int)Math.round(getSize().width * Math.random()); int y = (int)Math.round(getSize().height * Math.random()); int width = (int)Math.round(3 * Math.random()); switch (1 + (int)Math.round(2 * Math.random())) //either draw or erase stars { case 1: g.setColor(Color.white); g.fillRect(x, y, width, width); //draw a star break; case 2: g.setColor(Color.black); g.fillRect(x, y, 20*width, 20*width); //erase stars break; } //end of switch } //end of for i } //end of paint } //end of class Stars