【发布时间】:2017-05-23 19:54:50
【问题描述】:
所以我正在尝试制作一个计算器,我正在使用 JFrame 代码并尝试使用内置的 Math 来查找数字的平方根。下面的代码是我遇到问题的地方。 “display.setText(Math.sqrt(Double.parseDouble(display.getText())));”
给我错误“JTextComponent 类型中的方法 setText(String) 不适用于参数 (double)”
sqrt = new JButton("SQRT");
sqrt.setBounds(298, 141, 65, 65);
sqrt.setBackground(Color.BLACK);
sqrt.setForeground(Color.BLACK);
sqrt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setTempFirst(Double.parseDouble(display.getText()));
display.setText(Math.sqrt(Double.parseDouble(display.getText())));
operation[5] = true;
}
});
add(sqrt);
【问题讨论】:
标签: java string jframe value-of