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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题