import java.applet.*;
import java.awt.*;
import isi.jserver.jserver;

public class jcalc extends Applet
{
	TextField tf; TextArea ta; Button sj;
	jserver js;	boolean showflag;

	public void init()
	{
    	resize(600, 400);
		tf = new TextField("", 80);
		ta = new TextArea("", 16, 80);
		sj = new Button("Show J");
		add(tf); add(ta); add(sj);
		tf.setFont(new Font("Courier",Font.PLAIN,12));
		ta.setFont(new Font("Courier",Font.PLAIN,12));
		js = new jserver();	// create jserver object
		js.start(0);		// start jserver run thread
		js.Log(true);

		// load basic scripts - J3.05 and J4.01 different path and suffix
		js.Do("a_z_=:'4'=0{11!:0'qabout'");
		js.Do("z_z_=:>a_z_{'.js';'.ijs'");
		js.Do("a_z_=:>a_z_{'main\\';'system\\main\\'");
		js.Do("boot_z_=: 3 : '0!:0 <a,y.,z'");
		js.Do("boot_z_ 'stdlib'");
		js.Do("boot_z_ 'winlib'");
		js.Do("boot_z_ :: ] 'colib'   NB. only in J4.01");
		js.Do("boot_j_ :: ] 'loadlib' NB. only in J4.02");
		js.Do("boot_j_ 'jadelib'");   
		js.Do("boot_z_ :: ]'jadeutil' NB. only in older versions");

		js.Do("9!:7[1{9!:6''");	// box drawing +|
		tf.requestFocus();
	}

	public void destroy(){js.close();}

	public boolean action(Event ev, Object obj)
	{
		if(ev.target == tf)
		{
			byte[] bytes = new byte[50];
			String input = tf.getText();
			js.DoR(input);
			ta.appendText("   " + input + "\n");
			ta.appendText(js.getString());
			tf.setText("");
			return true;
		}
		if(ev.target == sj)
		{
			showflag = !showflag;
			js.Show(showflag);
			return true;
		}
		return false;
	}
}
