//FlashingCircles.java import java.awt.*; import javax.swing.*; public class FlashingCircles extends JApplet { int numOvals, maxWidth, maxHeight, minWidth, minHeight; public void init() { String input; input = JOptionPane.showInputDialog( "Enter number of ovals" ); numOvals = Integer.parseInt( input ); input = JOptionPane.showInputDialog( "Enter minimum width of ovals" ); minWidth = Integer.parseInt( input ); input = JOptionPane.showInputDialog( "Enter maximum width of ovals" ); maxWidth = Integer.parseInt( input ); input = JOptionPane.showInputDialog( "Enter minimum height of ovals" ); minHeight = Integer.parseInt( input ); input = JOptionPane.showInputDialog( "Enter maximum height of ovals" ); maxHeight = Integer.parseInt( input ); } public void paint (Graphics g) { int width = getWidth(); int height = getHeight(); int w, h, x, y; for (int i=1; i<=numOvals; i++) { //cycle thru these colors if (i%7 == 0) g.setColor(Color.RED); else if (i%7 == 1) g.setColor(Color.GREEN); else if (i%7 == 2) g.setColor(Color.BLUE); else if (i%7 == 3) g.setColor(Color.MAGENTA); else if (i%7 == 4) g.setColor(Color.CYAN); else if (i%7 == 5) g.setColor(Color.YELLOW); else g.setColor(Color.BLACK); //width and height of this oval w = (int)(Math.random()*(maxWidth-minWidth)+minWidth); h = (int)(Math.random()*(maxHeight-minHeight)+minHeight); //center point of this oval x = (int)(Math.random()*width); y = (int)(Math.random()*height); g.fillOval(x-w/2, y-h/2, w, h); } } }