从 jformatted 文本字段中获取浮点值
我能够创建仅接受浮点值的 JFormatted TextField,但我无法获取该值...... 我声明它..
stopAppFormattedTextField = new javax.swing.JFormattedTextField(new DecimalFormat("#.00"));
并使用 : 获取值
double stop=(Double)stopAppFormattedTextField.getValue();
,但上面的语句抛出以下异常:
“线程异常 “AWT-EventQueue-0” java.lang.ClassCastException: java.lang.Long 无法转换为 java.lang.Double"
我应该怎么做才能获取浮点值? -提前致谢
I am able to create JFormatted TextField that accepts only float values,but I am not able to fetch that value....
I am declaring it ..
stopAppFormattedTextField = new javax.swing.JFormattedTextField(new DecimalFormat("#.00"));
and fetching the value using :
double stop=(Double)stopAppFormattedTextField.getValue();
but the above statement is throwing the following exception:
"Exception in thread
"AWT-EventQueue-0"
java.lang.ClassCastException:
java.lang.Long cannot be cast to
java.lang.Double"
what should I do to fetch float values?
-Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您从格式化程序中获取了
Long
,但您需要double
。你可以这样做:You're getting
Long
s from the formatter, but you wantdouble
s. You can do this:初始化后将其添加到您的代码中:
getValue 将自动神奇地返回 double
Add this to your code after initialization:
The getValue will return double auto-magically