// DrawJPanel1Tester.java
// Applet tests the JPanel used as a dedicated drawing area
// APPLET CODE="DrawJPanel1Tester" HEIGHT=500 WIDTH=700
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DrawJPanel1Tester extends JApplet implements ActionListener, ItemListener {
	private Container c;
	private DrawJPanel1 pD;
	private JPanel pGUI;
	private JLabel wLabel, hLabel;
	private JTextField wField, hField;
	private JRadioButton redB, greenB;
	private ButtonGroup colorButtons;
	private int wid, hgt;
	private Color col = Color.red;	// initialize to red

	public void init( ) {
		c = getContentPane( );
		pD = new DrawJPanel1( );

		pGUI = new JPanel( );
		pGUI.setLayout( new GridLayout( 1, 6, 10, 10 ) );
		wLabel = new JLabel( "Enter the width:" );
		wField = new JTextField( 10 );
		wField.addActionListener( this );
					
		hLabel = new JLabel( "Enter the height:" );
		hField = new JTextField( 10 );
		hField.addActionListener( this );
		redB = new JRadioButton( "Red", true );
		redB.addItemListener( this );
		greenB= new JRadioButton( "Green", false );
		greenB.addItemListener( this );

		// create logical relationship between JRadioButtons
		colorButtons = new ButtonGroup( );
		colorButtons.add( redB );
		colorButtons.add( greenB );

		// add GUI components to pGUI panel
		pGUI.add( wLabel );
		pGUI.add( wField );
		pGUI.add( hLabel );
		pGUI.add( hField );
		pGUI.add( redB );
		pGUI.add( greenB );

		// add the panels to the container c		
		c.add( pGUI, BorderLayout.NORTH );
		c.add( pD, BorderLayout.CENTER );
	}

	public void actionPerformed( ActionEvent e ) {
		wid = Integer.parseInt( wField.getText( ) );
		hgt = Integer.parseInt( hField.getText( ) );
		pD.drawingStuff( col, wid, hgt );
	}

	public void itemStateChanged( ItemEvent e ) {
		if ( e.getSource( ) == redB )
			col = Color.red;
		else
			col = Color.green;

		wid = Integer.parseInt( wField.getText( ) );
		hgt = Integer.parseInt( hField.getText( ) );
		pD.drawingStuff( col, wid, hgt );
	}
}