/* CSE 142, Autumn 2007, Marty Stepp This program pops up DrawingPanels of random sizes between 200x200 and 500x500 every 500ms and randomly sets their background colors until we pop up 3 that are red. */ import java.awt.*; import java.util.*; // for Random public class DrawRandom { public static void main(String[] args) { Random randy = new Random(); int redCount = 0; while (redCount < 3) { int randomColor = createWindow(randy); if (randomColor == 1) { redCount++; } } } // creates and shows one drawing panel public static int createWindow(Random randy) { int size = randy.nextInt(300) + 200; DrawingPanel panel = new DrawingPanel(size, size); // random background color (1 is red, 2 is yellow, 3 is blue) int randomColor = randy.nextInt(3) + 1; if (randomColor == 1) { panel.setBackground(Color.RED); } else if (randomColor == 2) { panel.setBackground(Color.YELLOW); } else { panel.setBackground(Color.BLUE); } // pause 1/2 second between frames panel.sleep(500); return randomColor; } }