如何用 Java 开发多点触控应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/369301/
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
How to develop multi-touch applications in Java?
提问by David Koelle
Anticipating the day when multi-touch interfaces become more pervasive, are there libraries in Java that can be used for developing touch applications? I'm looking for interfaces similar to MouseListener / MouseMotionListener / MouseWheelListener.
期待多点触控界面变得更加普及的那一天,是否有 Java 库可用于开发触控应用程序?我正在寻找类似于 MouseListener / MouseMotionListener / MouseWheelListener 的接口。
采纳答案by Wayne
The MT4j project has everything you need to develop multitouch applications in java. All the well known multitouch gestures are already built in and can be accessed as simple as listening to mouse events (for example: component.addGestureListener(..)). It also features a hardware accelerated scene graph, similar to JavaFX. You can even simulate multitouch input by connecting one ore more mice to your machine. Check it out at http://www.mt4j.org
MT4j 项目拥有您在 Java 中开发多点触控应用程序所需的一切。所有众所周知的多点触控手势都已经内置,并且可以像监听鼠标事件一样简单地访问(例如:component.addGestureListener(..))。它还具有硬件加速的场景图,类似于 JavaFX。您甚至可以通过将一个或多个鼠标连接到您的机器来模拟多点触控输入。在http://www.mt4j.org 查看
回答by James Van Huis
Sparshis still in my bookmarks from the last time I was investigating multitouch java solutions.
从我上次研究多点触控 Java 解决方案开始,Sparsh仍然在我的书签中。
While not as straight forward as the typical mouse listener or click listener, it still provides a reasonable interface.
虽然不像典型的鼠标监听器或点击监听器那样直接,但它仍然提供了一个合理的界面。
You need your listening class to implement sparshui.client.Client
, which requires the processEvent
method definition.
你需要你的监听类来实现sparshui.client.Client
,这需要processEvent
方法定义。
public void processEvent(int groupID, Event event) {
if(event instanceof TouchEvent) {
TouchEvent e = (TouchEvent)event;
if(e.getState() == TouchState.BIRTH) {
//do initial touch stuff
} else if(e.getState() == TouchState.MOVE) {
//do dragging stuff
}
}
else if(event instanceof DragEvent) {
DragEvent e = (DragEvent)event;
//do DragEvent specific stuff
} else if(event instanceof RotateEvent) {
RotateEvent e = (RotateEvent)event;
//do RotateEvent specific stuff
} else if(event instanceof ZoomEvent) {
ZoomEvent e = (ZoomEvent)event;
//do ZoomEvent specific stuff
}
//several other gesture types....
}
After that, you need to start up the gesture recognition server, passing in your component
之后,您需要启动手势识别服务器,传入您的组件
new ServerConnection("localhost", objectImplementingClientInterface);
Looking at the code examples on the site should give you a pretty good idea of the framework.
查看站点上的代码示例应该会让您对框架有一个很好的了解。
回答by Wayne
How about this: http://kenai.com/projects/macmultitouch
回答by meta-meta
I am primarily working in Processing and designing my UI from the ground up. I've been looking for a solution which doesn't prescribe a UI framework which both MT4J and JavaFX appear to do. Furthermore, MT4J appears to be abandoned.
我主要从事处理和从头开始设计我的 UI。我一直在寻找一种解决方案,它没有规定 MT4J 和 JavaFX 似乎都具有的 UI 框架。此外,MT4J 似乎已被放弃。
This looks like a promising solution at least for Windows but I'm unsure if it's actually released yet: http://wiki.gestureworks.com/index.php/GestureWorksCore:Gestureworks_Core_Tutorials
至少对于 Windows,这看起来是一个很有前途的解决方案,但我不确定它是否真的发布了:http: //wiki.gestureworks.com/index.php/GestureWorksCore: Gestureworks_Core_Tutorials
This is specifically for Processing, cross-platform, open-source and active: https://github.com/vialab/SMT
这是专门为处理,跨平台,开源和活跃:https: //github.com/vialab/SMT
回答by benliet
MT4Jdoesn't work with Windows 8.
MT4J不适用于 Windows 8。
If the applicatin is only for one user, you can use JavaFX. There are different listener for touch events. But it is not possible to process two gestures at the same time, because all touch points will merge to one gesture. For big multi touch screens it is a disadvange. For normal screens, where is only one user its ok.
如果应用程序仅适用于一位用户,则可以使用JavaFX。触摸事件有不同的侦听器。但是不可能同时处理两个手势,因为所有的触摸点都会合并为一个手势。对于大型多点触摸屏,这是一个缺点。对于普通屏幕,只有一个用户可以。
But there is also GestureWorks. There you can define new gesture or use the predefined gesture. The gestures are defined in a XML File (called GML). Any object can handle there own gestures. But you have to implement the hitTest and the point assignment manually. But there is a greate tutorial.
但也有GestureWorks。您可以在那里定义新手势或使用预定义的手势。手势在 XML 文件(称为 GML)中定义。任何对象都可以处理自己的手势。但是您必须手动实现 hitTest 和点分配。但是有一个很棒的教程。
Another library, which i don't tested, ist the Multi Touch SDK by PQ Lab.
另一个我没有测试过的库是 PQ Lab的Multi Touch SDK。