// GrowingCubePanel.java
// JPanel dedicated to drawing a growing cube
// A cube that contracts up to a point and then expands as a button is pushed
// Cube is drawn as an outline - it is not filled
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class GrowingCubePanel extends JPanel {
	int x = 20;		// upper left corner x coord
	int y = 180;	// upper left corner y coord
	int w; 		// width of the cube

	public void drawInfo( int width ) {
		w = width;
		repaint( );
	}

	public void paintComponent( Graphics g ) {
		// call super paintComponent
		super.paintComponent( g );

		Graphics2D g2d = ( Graphics2D ) g;
		g2d.setColor( Color.white );
		g2d.fillRect( 0, 70, 400, 330 );
		g2d.setPaint( Color.red );
		g2d.setStroke( new BasicStroke( 10.0f ) );
		g2d.draw( new Rectangle2D.Double( x, y, w, w ) );
		g2d.draw( new Line2D.Double( x, y, x + ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ), y - ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ) ) );  // #1
		g2d.draw( new Line2D.Double( x + w, y, x + w + ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ), y - ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ) ) );  // #2
		g2d.draw( new Line2D.Double( x + w, y + w, x + w + ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ), y + w - ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ) ) );  // #3
		g2d.draw( new Line2D.Double( x + w + ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ), y - ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ), x + w + ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ), y + w - ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ) ) );  // #4
		g2d.draw( new Line2D.Double( x + ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ), y - ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ), x + w + ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ), y - ( int ) ( w / ( 2 * Math.sqrt( 2 ) ) ) ) );  // #5
	}
}