プログラムソースです。
import java.applet.*;
import java.awt.*;

public class test_5 extends Applet{

	Button but_1, but_2, but_3, but_4, but_5, but_6, but_7, but_8, but_9, but_0;
	Button tasu, ikoru, ac, c;
	TextField tf;
	int i;
	String buf, str="", str_2="";
	int a=0, b=0;

	public void init(){
		setLayout(new BorderLayout());

		Panel textpanel = new Panel();
		textpanel.setLayout(new FlowLayout());
		textpanel.add(tf=new TextField("", 15));
		add("North",textpanel);

		Panel gridpanel =  new Panel();
		gridpanel.setLayout(new GridLayout(5,4));
		gridpanel.add(but_1=new Button("1"));
		gridpanel.add(but_2=new Button("2"));
		gridpanel.add(but_3=new Button("3"));
		gridpanel.add(but_4=new Button("4"));
		gridpanel.add(but_5=new Button("5"));
		gridpanel.add(but_6=new Button("6"));
		gridpanel.add(but_7=new Button("7"));
		gridpanel.add(but_8=new Button("8"));
		gridpanel.add(but_9=new Button("9"));
		gridpanel.add(but_0=new Button("0"));
		gridpanel.add(tasu = new Button("+"));
		gridpanel.add(ikoru = new Button("="));
		gridpanel.add(ac = new Button("AC"));
		gridpanel.add(c = new Button("C"));
		add("South",gridpanel);
	}

	public boolean action(Event e, Object o){
		if(e.target == but_1){
			buf = "1";
			str = str + buf;
			tf.setText(str);
		}
		else if(e.target == but_2){
			buf = "2";
			str = str + buf;
			tf.setText(str);
		}
		else if(e.target == but_3){
			buf = "3";
			str = str + buf;
			tf.setText(str);
		}
		else if(e.target == but_4){
			buf = "4";
			str = str + buf;
			tf.setText(str);
		}
		else if(e.target == but_5){
			buf = "5";
			str = str + buf;
			tf.setText(str);
		}
		else if(e.target == but_6){
			buf = "6";
			str = str + buf;
			tf.setText(str);
		}
		else if(e.target == but_7){
			buf = "7";
			str = str + buf;
			tf.setText(str);
		}
		else if(e.target == but_8){
			buf = "8";
			str = str + buf;
			tf.setText(str);
		}
		else if(e.target == but_9){
			buf = "9";
			str = str + buf;
			tf.setText(str);
		}
		else if(e.target == but_0){
			buf = "0";
			str = str + buf;
			tf.setText(str);
		}

		else if(e.target == tasu){
			a = Integer.parseInt(str);
			b = b + a;
			str = new String();
			str_2 = String.valueOf(b);
			tf.setText(str_2);
			str_2 = new String();
		}

		else if(e.target == ikoru){
			a = Integer.parseInt(str);
			b = b + a;
			str = new String();
			str_2 = String.valueOf(b);
			tf.setText(str_2);
			str_2 = new String();
			b = 0;
			str = new String();
			str = "";
		}
		else if(e.target == ac){
			b = 0;
			a = 0;
			str = new String();
			str = "";
			tf.setText(str);
		}
		else if(e.target == c){
			a = 0;
			str = new String();
			str = "";
			tf.setText(str);
		}
		return true;
	}
}
戻る