// OvalPanel.java // Customized JPanel class import java.awt.*; import javax.swing.*; public class OvalPanel extends JPanel { private int dia = 10; public void paintComponent( Graphics g ) { super.paintComponent( g ); // delete this to keep JPanel from clearing background but gives unexpected results g.fillOval( 10, 10, dia, dia ); } public void setDiameter( int d ) { dia = ( d >= 0 ? d : 10 ); // default value is 10 repaint( ); } // following methods are used by layout managers public Dimension getPreferredSize( ) { return new Dimension( 200, 200 ); } public Dimension getMinimumSize( ) { return getPreferredSize( ); } }