// GrowingSquarePanel2D.java
// JPanel dedicated to drawing a growing square and circle
// Ugly circle inside an ugly square
// Both expand and contract together
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.image.*;

public class GrowingSquarePanel2D 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 );
		Graphics2D g2d = ( Graphics2D ) g;
		Rectangle2D.Double rectBack = new Rectangle2D.Double( 0, 70, 400, 330 );

		// clear the background
		//g2d.setColor( Color.white );
		GradientPaint gp1 = new GradientPaint( 0, 0, Color.blue, 10, 10, Color.red, true );
		g2d.setPaint( gp1 );
		g2d.fill( rectBack );

		// draw with a buffered background
		BufferedImage buffImage = new BufferedImage( 5, 5, BufferedImage.TYPE_INT_RGB );
		Graphics2D gg = buffImage.createGraphics( );
		gg.setColor( Color.cyan );
		gg.fillRect( 0, 0, 5, 5 );
		gg.setColor( Color.black );
		gg.fillOval( 1, 1, 3, 3 );
		// paint buffImage onto the applet
		g2d.setPaint( new TexturePaint( buffImage, new Rectangle( 5, 5 ) ) );
		Rectangle2D.Double square = new Rectangle2D.Double( sx, sy, sw, sw );
		g2d.fill( square );
		// draw circle inside the square
		//GradientPaint gp1 = new GradientPaint( 0, 0, Color.blue, 10, 10, Color.red, true );
		g2d.setPaint( gp1 );
		Ellipse2D.Double circle = new Ellipse2D.Double( cx, cy, d, d );
		g2d.fill( circle );
	}
}