Code_2017 2018-04-25 07:51 采纳率: 0%
浏览 1692
已结题

empty string的界面问题

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条回答

  • smallsmall英 2018-04-26 02:59
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件