// GrowingSquarePanel2DTester.java
// Ugly circle inside an ugly square
// Both expand and contract together
// APPLET CODE="GrowingSquarePanel2DTester" HEIGHT=480 WIDTH=400
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class GrowingSquarePanel2DTester extends JApplet {
	int sx, sy, sw;
	int growFactor, move;

	// GUI Component
	Container c;
	JPanel pGUI;
	GrowingSquarePanel2D pD;
	JButton b;

	public void init( ) {
		sx = 100;
		sy = 100;
		sw = 200;
		growFactor = 10;
		move = 5;

		c = getContentPane( );
		pGUI = new JPanel( );
		pGUI.setLayout( new FlowLayout( ) );
		b = new JButton( "Push" );
		b.addActionListener(
			new ActionListener( ) {
				public void actionPerformed( ActionEvent e ) {
					if ( sw >= 200 || sw <= 20 ) {
						growFactor *= -1;
						move *= -1;
					}

					sw += growFactor;
					sx -= move;
					sy -= move;
					pD.drawInfo( sw, sx, sy );
				}
			}
		);
		pGUI.add( b );

		pD = new GrowingSquarePanel2D( );
		c.add( pGUI, BorderLayout.NORTH );
		c.add( pD, BorderLayout.CENTER );
		pD.drawInfo( sw, sx, sy );
	}
}