请教,Awt如何实现计算器功能。比如点按钮1,文本框出现1,再点2,文本框出现12 。这样,我现在写出来, 点1 出现1 ,点2 就把1覆盖了,
感觉 应该很简单就解决了,但我好像走到胡同里了, 新手 见谅。麻烦大家了
只要解决这一点 应该 我就能写完整了。
最好有新手仅学的这点知识,有更简单的写法。各位大神 ,请教了
import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class JiSuan extends Frame implements WindowListener,ActionListener{
Label l1=new Label("编辑");
Label l2=new Label("查看");
Label l3=new Label("帮助");
TextField t1=new TextField();
Button b1=new Button("back space");
Button b2=new Button("CE");
Button b3=new Button("c");
Button b4=new Button("7");
Button b5=new Button("8");
Button b6=new Button("9");
Button b7=new Button("/");
Button b8=new Button("+");
Button b9=new Button("4");
Button b10=new Button("5");
Button b11=new Button("6");
Button b12=new Button("*");
Button b13=new Button("%");
Button b14=new Button("1");
Button b15=new Button("2");
Button b16=new Button("3");
Button b17=new Button("0");
Button b18=new Button("-");
public JiSuan(){
this.setSize(350,280);
this.setTitle("计算器");
this.setLayout(null);
this.addWindowListener(this);
this.setBackground(Color.cyan);
l1.setBounds(10, 30, 40,30);
l2.setBounds(50, 30, 40,30);
l3.setBounds(90, 30, 50, 30);
t1.setBounds(10, 60, 250, 25);
b1.setBounds(20, 100, 70, 30);
b2.setBounds(130, 100, 45, 30);
b3.setBounds(220, 100, 45, 30);
b4.setBounds(20, 140, 45, 20);
b5.setBounds(80, 140, 45, 20);
b6.setBounds(140, 140, 45, 20);
b7.setBounds(200, 140, 45, 20);
b8.setBounds(260, 140, 45, 20);
b9.setBounds(20, 170, 45, 20);
b10.setBounds(80, 170, 45, 20);
b11.setBounds(140, 170, 45, 20);
b12.setBounds(200, 170, 45, 20);
b13.setBounds(260, 170, 45, 20);
b14.setBounds(20, 200, 45, 20);
b15.setBounds(80, 200, 45, 20);
b16.setBounds(140, 200, 45, 20);