// MonteCarlo.java// Written by Julian Devlin, 8/97, for the text book// "Introduction to Probability," by Charles M. Grinstead & J. Laurie Snell// RESIZE POINTS// Better y axis// Add other functions - use constants// Variable window size??// Show points as they are calculated?import java.applet.Applet;import java.awt.*;public class MonteCarlo	extends java.applet.Applet{	MCSquareGraph mcsg;				// AWT elements	Label message;	Button go;	TextField numPts;	Label results;			Panel graphArea;	Panel controls;	// Set up all controls and put them in the window	public void init() {		message = new Label("Random points =");	// Create controls		go = new Button("Simulate");		numPts = new TextField(4);		results = new Label("Estimate of area is        ");				graphArea = new Panel();				// Set up window		controls = new Panel();		setLayout(new BorderLayout());			controls.setLayout(new FlowLayout());		controls.add(message);		controls.add(numPts);		controls.add(go);		controls.add(results);				mcsg = new MCSquareGraph(0, 1); // initialize a graphing space		add("Center", mcsg);		add("South", controls);	}		// Does the simulation, creating two arrays to store game states, then passes them	// to a SpikeGraph	public void simulate() {		int np = 0;		float area;		try {			np = Integer.parseInt(numPts.getText().trim());	// Get user input		}		catch (Exception e) {			numPts.setText("");			validate();		}				remove(mcsg);		mcsg = new MCSquareGraph(0, 1);			// Create new SpikeGraph		add("Center", mcsg);							// Put up the graph		validate();		area = mcsg.setRandPts(np);		results.setText("Estimate of area is " + String.valueOf(area));		validate();	}		// Watch for a click on the go button	public boolean action(Event evt, Object arg) {		if (evt.target instanceof Button) {			if ((String)arg == "Simulate") {				simulate();			}		}		return true;	}		public Insets insets() {    	return new Insets(5,5,5,5);	}}
