在SWT上点击鼠标点击事件

在SWT上点击鼠标点击事件

本文介绍了在SWT上点击鼠标点击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SWT中,对于MouseListener接口,可用的方法是 mouseUp() mouseDown() mouseDoubleClick()

In SWT, for MouseListener interface, the methods available are mouseUp(), mouseDown() and mouseDoubleClick()

如何根据用户点击触发事件?

How to fire an event based on the user click?

我们可以通过 mouseUp() mouseDown()的结合来做到这一点但是在SWT中是不是有像 mouseClick()方法的任何简单解决方案?

We can do this by conjunction of mouseUp() and mouseDown() but isn't there any trivial solution like mouseClick() method in SWT?

谢谢。

推荐答案

如何定义鼠标点击事件?鼠标按下然后鼠标向上,没有鼠标离开控件的边界(否则它将是拖动开始),对吧?根据该定义,鼠标单击事件不能与单个点相关联,而是与区域(1)或控件(2)相关联。第一种情况不适合通用SWT事件,它只有一个位置(x和y),你还需要额外的代码来检查点击区域是否在你的图像中。在第二种情况下,鼠标点击只能使用一个控件(而且没有位置)来定义,这个事件对你来说是没用的。

How would a mouse-click event be defined? Mouse-down followed by mouse-up without mouse leaving the bounds of the control (otherwise it would be drag-start), right? By that definition, mouse-click event couldn't be associated with a single point, but rather with an area (1) or a control (2). The first case wouldn't fit into generic SWT event, which only has a location (x and y), and you'd still need additional code to check whether the click area was inside your image. In the second case where the mouse-click would only be defined using a control (and no location), the event would be useless to you.

当你实现了您可以通过单击检测来触发您喜欢的控件上的任何事件,甚至是那些未由SWT定义的事件。

When you have implemented your own single-click detection you can fire any events on the control you like, even those not defined by SWT.

这篇关于在SWT上点击鼠标点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 07:07