我能够创建仅接受浮点值的 JFormatted TextField,但我无法获取该值.... 我宣布..
stopAppFormattedTextField = new javax.swing.JFormattedTextField(new DecimalFormat("#.00"));
并使用 :
获取值double stop=(Double)stopAppFormattedTextField.getValue();
但上面的语句抛出以下异常:
"Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Double"
我应该怎么做才能获取浮点值? -提前致谢
最佳答案
您从格式化程序中得到了 Long
,但是您想要 double
。你可以这样做:
Number number = (Number)stopAppFormattedTextField.getValue();
double stop = number.doubleValue();
关于java - 从 jformatted 文本字段中获取浮点值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3759424/