// OvalDrawing.java // A solution to CS 5JA assignment 4, part 1, Winter 2009 // cmc, updated 2/9/09 import java.awt.Graphics; import javax.swing.JPanel; public class OvalDrawing extends JPanel { private int ovals; // number of ovals to draw // constructor sets the number of ovals public OvalDrawing(int number) { ovals = number; } // draws the ovals public void paintComponent(Graphics g) { super.paintComponent( g ); double width = getWidth(), height = getHeight(); // find size of the smallest oval double smallestWidth = width / ovals; double smallestHeight = height / ovals; // find the middle of the panel double centerX = width / 2; double centerY = height / 2; // draw ovals starting with the innermost (smallest) one double x, y, w, h; for (int i = 1; i <= ovals; i++) { w = i * smallestWidth; h = i * smallestHeight; x = centerX - w / 2; y = centerY - h / 2; g.drawOval((int)x, (int)y, (int)w, (int)h); } } }