// OvalDrawingTest.java // Use AS-IS to test CS 5JA assignment 4, part 1, Winter 2009 // cmc, updated 2/9/09 import javax.swing.JFrame; import java.util.Scanner; public class OvalDrawingTest { public static void main(String args[]) { final int MIN = 1, MAX = 50; final int WIDTH = 400, HEIGHT = 400; // let user select number of ovals - limited from MIN to MAX int n = 0; Scanner input = new Scanner(System.in); do { System.out.printf("Enter number of ovals (%d-%d): ", MIN, MAX); // make sure an int is entered before trying to read it if (input.hasNextInt()) { n = input.nextInt(); // inform user if n is out of range if (n < MIN) System.out.println(n + " is too few. Try again."); else if (n > MAX) System.out.println(n + " is too many. Try again."); } else { // int was not entered String badData = input.next(); System.err.println("ERROR - not integer: " + badData); } } while (n < MIN || n > MAX); // some frame "plumbing" including a customized title String title = String.format("%s%d", "Number of ovals: ", n); JFrame frame = new JFrame(title); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setSize(WIDTH, HEIGHT); // create and add the drawing, and show the frame OvalDrawing drawing = new OvalDrawing(n); frame.add(drawing); frame.setVisible(true); } }