package rpn.vc;

import java.applet.*;
import java.awt.*;
import rpn.*;

/* This can serve for extension to be used as exercise applets. */

public class vcApplet extends Applet {

	public CalculatorPanel vc = null;
	public String initString = null;
	public String title = null;
	
	public void init() {
		int i = 0;
		setLayout(new BorderLayout(0, 0));
		int w = bounds().width; int h = bounds().height - 84;
		int r = 10;
		String rows = getParameter("rows");
		if (rows != null) {
			r = Integer.parseInt(rows);
		}
		// System.out.println("row number = " + r);
		String s = null;
		if (initString == null) {
			initString = getParameter("initialString") + "\n";
			if (initString == null) initString = "";
        	}

		title = getParameter("title");
		if (title == null) title = "VC";
		vc = new CalculatorPanel(r, initString, title, 
			new VCInterpreter(), 
			new VCInstaller());
		// add("Center", vc);
		add("Center", vc);
		show();
		// System.out.println("initializing [" + count++ + "]");;
	}
	
	int count = 0;
	public void start() {
		vc.frameInit();
		vc.inputArea.setText(initString);
		System.out.println("starting " + title);
	}
	
	public void stop() {
		initString = vc.inputArea.getText();
		vc.frameDestroy();
		System.out.println("stopping " + title);
		vc.stop();
	}
	
	public void destroy() {
		initString = vc.inputArea.getText();
		vc.frameDestroy();
		System.out.println("killing " + title);
		vc.stop();
	}
}
