// GrowingSquarePanel.java // JPanel dedicated to drawing a growing square and circle // Black circle inside a red square // Both expand and contract together import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class GrowingSquarePanel extends JPanel { int sx, sy, sw; int cx, cy, d; public void drawInfo( int sWidth, int sXCoord, int sYCoord ) { // square size and placement sw = sWidth; sx = sXCoord; sy = sYCoord; // calculate circle size and placement d = sw - 10; cx = sx + 5; cy = sy + 5; repaint( ); } public void paintComponent( Graphics g ) { super.paintComponent( g ); // clear the background g.setColor( Color.white ); g.fillRect( 0, 70, 400, 330 ); // draw the square g.setColor( Color.red ); g.fillRect( sx, sy, sw, sw ); // draw the circle g.setColor( Color.black ); g.fillOval( cx, cy, d, d ); } }