java 使用 SWING 编写触摸屏应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4707101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Programming a touch screen application with SWING
提问by tomericco
I would like to know what events my buttons in the UI of my application should have listen to? To mouse click? And what about the pressing and releasing events? Are they the same while clicking via touch screen?
我想知道我的应用程序 UI 中的按钮应该监听哪些事件?鼠标点击?那么按下和释放事件呢?通过触摸屏单击时它们是否相同?
Thanks, Tomer
谢谢,托默
回答by Stewart Murrie
Most touchscreens simply emulate a mouse, so if your needs are simple you don't need to do anything special - JButtons still fire ActionEvents, combo boxes still fire ItemEvents, etc. If you want to do anything fancy (multitouch, flick-scrolling, etc.) then you can use the regular mouse events (mouseClicked, mousePressed, mouseDragged etc.) and provide your own gesture logic, or take a look at the libraries suggested in the answer for this similar question.
大多数触摸屏只是模拟鼠标,所以如果你的需求很简单,你不需要做任何特别的事情 - JButtons 仍然会触发 ActionEvents,组合框仍然会触发 ItemEvents 等等。如果你想做任何奇特的事情(多点触控、轻弹滚动、等)然后您可以使用常规鼠标事件(mouseClicked、mousePressed、mouseDragged 等)并提供您自己的手势逻辑,或查看此类似问题的答案中建议的库。