import java.awt.*;
import java.awt.event.*;
public class simpleCalc {
public static void main(String args[]){
new myFrame03().loadFrame();
}
}
class myFrame03 extends Frame{
public TextField text1;
public TextField text2;
public TextField text3;
public void loadFrame(){
TextField text1 = new TextField(10);
TextField text2 = new TextField(10);
TextField text3 = new TextField(20);
Label label = new Label("+");
Button buttonc = new Button("=");
buttonc.addActionListener(new calcAction());
setLayout(new FlowLayout());
add(text1);
add(label);
add(text2);
add(buttonc);
add(text3);
setBounds(100,100,300,150);
pack();
setVisible(true);
}
class calcAction implements ActionListener{
public void actionPerformed(ActionEvent e){
float i=Float.parseFloat(text1.getText());
float j=Float.parseFloat(text2.getText());
String k=Float.toString(i+j);
text3.setText(k);
text2.setText("");
text1.setText("");
}
}
}
局部变量把 全局变量给覆盖了导致后面无效,嗯 自问自答。。一直在看其他地方出问题没 好家伙 想扇死自己
你好,我是有问必答小助手。为了技术专家团更好地为您解答问题,烦请您补充下(1)问题背景详情,(2)您想解决的具体问题,(3)问题相关代码图片或者报错信息。便于技术专家团更好地理解问题,并给出解决方案。
您可以点击问题下方的【编辑】,进行补充修改问题。