简体   繁体   English

Java替代AWT来捕获鼠标事件?

[英]Java alternatives to AWT to capture mouse events?

是否有AWT的替代方法可以在Java中获取鼠标按下事件?

Mouse event implies there's a window / frame on which the event occurred. 鼠标事件表示事件发生在一个窗口/框架上。 Typically each GUI toolkit comes with its own list of event listeners / dispatchers. 通常,每个GUI工具箱都带有自己的事件侦听器/调度程序列表。 So the question should really be: "What are the alternatives to AWT?" 因此,问题实际上应该是: “ AWT的替代品有哪些?”

  1. There's Swing . 秋千 You can read about the difference between AWT and Swing here . 您可以在此处阅读有关AWT和Swing之间的区别。 (The answer also mentions SWT : (答案还提到了SWT

Finally, you might also want to check out SWT (the GUI toolkit used for Eclipse, and an alternative to both AWT and Swing), which is somewhat of a return to the AWT idea of accessing native Widgets through Java. 最后,您可能还想看看SWT(用于Eclipse的GUI工具包,是AWT和Swing的替代品),这有点像是通过Java访问AWT的想法的AWT理念的回归。

  1. There's JavaFX , which is a more rich graphics framework and somewhat a successor of Swing. JavaFX是一个更丰富的图形框架,在某种程度上是Swing的继承者。 You can read about it on official Oracle JavaFX page here . 您可以在此处的 Oracle JavaFX官方页面上阅读有关它的信息

If we are talking about specific frameworks then (as far as I know they still use AWT event system underneath): 如果我们在谈论特定的框架,那么(据我所知,它们仍然在下面使用AWT事件系统):

  1. JMonkey game engine. JMonkey游戏引擎。 Official Page 官方网站

  2. LWJGL . LWJGL Light weight java gaming library. 轻量级Java游戏库。 Official Page 官方网站

There are probably other frameworks but it seems the core functionality comes from AWT to handle native mouse query. 可能还有其他框架,但似乎核心功能来自AWT来处理本机鼠标查询。

Since I found lots of unanswered threads on this I'll share the solution. 由于我发现了许多未解决的问题,因此我将分享解决方案。 Turns out Windows 7 defaults Java to wm_gesture rather than wm_touch events so AWT does not get press events as expected. 事实证明,Windows 7默认将Java设置为wm_gesture而不是wm_touch事件,因此AWT无法获得预期的新闻事件。 What you need to do is use JNA to register the window as a touch window ( https://msdn.microsoft.com/en-us/library/windows/desktop/dd317326(v=vs.85).aspx ). 您需要做的是使用JNA将窗口注册为触摸窗口( https://msdn.microsoft.com/zh-cn/library/windows/desktop/dd317326(v=vs.85).aspx )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM