// RepaintJPanelDemo.java
// Simple of demo of paint vs. repaint
// APPLET CODE="RepaintJPanelDemo" HEIGHT=500 WIDTH=800
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class RepaintJPanelDemo extends JApplet implements ActionListener {
	int w, h;
	Container c;
	JPanel pGUI;
	RepaintJPanel pD;
	JLabel labelW, labelH;
	JTextField inputW, inputH;

	public void init( ) {
		// initialize dimensions
		w = 100;
		h = 100;

		// create the container
		c = getContentPane( );

		pGUI = new JPanel( );
		pGUI.setLayout( new GridLayout( 1, 4, 5, 5 ) );

		// create and add the labels and text fields to pGUI
		labelW = new JLabel( "Enter the integer width" );
		pGUI.add( labelW );
		inputW = new JTextField( 10 );
		inputW.addActionListener( this );
		pGUI.add( inputW );

		labelH = new JLabel( "Enter the integer height" );
		pGUI.add( labelH );
		inputH = new JTextField( 10 );
		inputH.addActionListener( this );
		pGUI.add( inputH );

		// create and add the drawing panel
		pD = new RepaintJPanel( );

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

	public void actionPerformed( ActionEvent e ) {
		// convert the two text field inputs into integers
		// and pass to JPanel
		w = Integer.parseInt( inputW.getText( ) );
		h = Integer.parseInt( inputH.getText( ) );
		pD.passDim( w, h );
	}
}