//ColorCircleApplet.java import java.awt.*; import javax.swing.*; public class ColorCircleApplet extends JApplet { int colorNumber; public void init() { String input; input = JOptionPane.showInputDialog( "Enter number of color " + "\n" + "1=Red 2=Blue 3=Green 4=Cyan 5=Magenta 6=Yellow 7= White 8=Black"); colorNumber = Integer.parseInt( input ); } public void paint (Graphics g) { if (colorNumber == 1) g.setColor(Color.RED); else if (colorNumber == 2) g.setColor(Color.BLUE); else if (colorNumber == 3) g.setColor(Color.GREEN); else if (colorNumber == 4) g.setColor(Color.CYAN); else if (colorNumber == 5) g.setColor(Color.MAGENTA); else if (colorNumber == 6) g.setColor(Color.YELLOW); else if (colorNumber == 7) g.setColor(Color.WHITE); else g.setColor(Color.BLACK); //any other number //Math.random() returns random double between 0 and 1 //Math.random()*100 evaluates to double between 0 and 100 //(int)(Math.random()*100) casts (converts) to int between 0 and 99 //draw randomly sized oval in random place: g.fillOval((int)(Math.random()*getWidth()), (int)(Math.random()*getHeight()), (int)(Math.random()*300), (int)(Math.random()*300)); } } /* show Math.random() show Math.random()*100 show (int)(Math.random()*100) circle not uniformly distributed aon applet area, change so x,y is center of oval fixed size display the random values too heads/tails min--max range Circle completely within applet area. */