empty string的界面问题 5C

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Computer extends Frame implements ActionListener{
Button bt_add = new Button("+");
Button bt_sub = new Button("-");
Button bt1 = new Button("1");
Button bt2 = new Button("2");
Button bt3 = new Button("3");
TextField txt1 = new TextField();
TextField txt2 = new TextField();
TextField txt3 = new TextField();
TextField txt4 = new TextField();
public Computer() {

    this.setLayout(new FlowLayout());
    this.add(txt1);
    this.add(txt2);
    this.add(txt3);
    this.add(txt4);

    this.add(bt1);
    this.add(bt2);
    this.add(bt3);
    this.add(bt_add);
    this.add(bt_sub);

    bt1.addActionListener(this);
    bt2.addActionListener(this);
    bt3.addActionListener(this);
    bt_add.addActionListener(this);
    bt_sub.addActionListener(this);
    this.addWindowListener(new Windows());
}
@Override
public void actionPerformed(ActionEvent e) {
    double d1,d2,result;
    String op;
    d1 = Double.parseDouble(txt1.getText());
    d2 = Double.parseDouble(txt3.getText());

    op = txt2.getText();
    if(op.equals("+") ) {
        result = d1+d2;
        txt4.setText(Double.toString(result));
    }
    else if(op.equals("-")) {
        result = d1-d2;
        txt4.setText(Double.toString(result));
    }
}

public static void main(String[] args) {
    Computer c = new Computer();
    c.setSize(240,240);
    c.setVisible(true);
}

}
class Windows extends WindowAdapter{
public void WindowClosing(WindowEvent e) {
System.exit(2);
}
}

2个回答

请把报错的截图发出来,empty string没有办法定位问题在哪里

请把报错的截图发出来 ,是不好定位的

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐