【发布时间】:2016-04-13 16:57:15
【问题描述】:
我的程序适用于生日和年龄。我在尝试将我的 JTextField 字符串转换为双精度时遇到了麻烦。我使用了 parse 方法,但仍然收到错误。请帮忙!
public class MyPaymentFrame extends JFrame implements ActionListener {
JTextField txtAge;
JTextField txtDate;
public MyPaymentFrame() {
Container mycnt = getContentPane();
mycnt.setLayout(new FlowLayout());
Color c = new Color(56, 100, 20);
Font F = new Font("Arial", Font.ITALIC, 20);
mycnt.add(new JLabel("Enter your Age"));
txtAge = new JTextField(15);
mycnt.add(txtAmount);
mycnt.add(new JLabel("Enter birthdate"));
txtDate = new JTextField(10);
mycnt.add(txtDate);
}
if (e.getActionCommand().equals("Clear")) {
txtAge.setText("");
txtDate.setText("");
}
if (e.getActionCommand().equals("Calculate")) {
// Converting String to Double
double Amount = Double.parseDouble(txtMonth);
}
}
public static void main(String[] args) {
Theframe myframe = new Theframe();
}
}
【问题讨论】:
-
你遇到了什么错误?
-
您是否尝试打印
txtMonth来排除故障...?这应该是第一步...... -
代码无法编译。
标签: java string double jtextfield