Java TextField 问题
我正在尝试构建一个接受长度(例如飞机机翼的跨度)的自定义文本字段类。我可以设置默认单位系统,例如“英寸”、“英尺”、“米”等,但我也希望能够输入默认单位系统中没有的长度。
例如,如果我的默认单位系统是“米”,我希望能够在文本字段中输入“10.8 英尺”,然后从英尺转换为米。
有谁知道是否有此类编码的示例?我搜索并找到了一个只接受数字的文本字段(在 NumericTextField),但这不适合我的需要,因为我想输入“10 ft”或“8.5 m”。
I am trying to build a custom text field class that accepts lengths (the span of aircraft wings, for example). I can set default unit system such as "inches", "feet", "meters" etc. but I would also like to be able to input lengths that are not in the default unit system.
So for example, if my default unit system is "meters", I would like to be able to input "10.8 ft" in my text field and then convert from ft to meters.
Does anyone know if there is an example of this type of coding? I have searched and found a text field that only accepts numerics (in NumericTextField), but this does not suit my needs because I would like to input "10 ft" or "8.5 m".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个解决方案:
我很快就做到了。如果需要,您可以通过添加更多方法和单元来改进它。
Here is a solution:
I made this qucikly. You can improve it by adding more methods and units if you need.
JScience
为org.jscience.physicals.amount
。JScience
provides support for strongly typed physical quantities and operations inorg.jscience.physics.amount
.