学了一晚上然后试着写了下,有bug未能发现原因,第一次点击1+1之后会有一个变成0,后面就正常了
public class st12 {
public static void main(String[] args) {
// 建议加减乘除计算器
new MyFrame6().loadFrame();
}
}
class MyFrame6 extends Frame {
TextField textField;
int count1=0;
String f;
int count2=0;
public void loadFrame(){
setLayout(new GridLayout(2,1));
Panel top = new Panel();
textField = new TextField(10);
top.add(textField);
top.setBackground(Color.GRAY);
Panel bot = new Panel(new GridLayout(1,2));
Panel left = new Panel(new GridLayout(5,2));
for (int i = 0; i < 10; i++) {
Button button = new Button(""+i);
button.addActionListener(new MyActionListener());
left.add(button);
}
Panel right = new Panel(new GridLayout(5,1));
Button button = new Button("+");