1

目前在我的(JRuby 代码)中,我想以不同于“双击托盘图标”(awt.TrayIcon 实例)的方式处理“气球关闭”消息:

import java.awt.TrayIcon
import java.awt.event.MouseListener

tray = java.awt.SystemTray::system_tray
image = java.awt.Toolkit::default_toolkit.get_image('')

trayIcon = TrayIcon.new(image, 'name', nil)

tray.add(trayIcon)
trayIcon.addActionListener do |evt|
  puts "in here", evt.id
end
trayIcon.displayMessage("title", "try clicking within the baloon, but not the x, then double clicking the tray icon", TrayIcon::MessageType::INFO)
puts "try clicking within the balloon message, or double clicking, both seem to generate the same event"

和java中的等效代码https://gist.github.com/4338167

当 1) 用户双击系统托盘中的图标,或 2) 用户通过单击气球(而不是 x)关闭托盘最近的气球消息时,似乎会调用此操作侦听器。

是否可以区分两种不同的事件类型(两者似乎都有事件 id 1001),还是我必须通过相对时间或其他方式来推断它?或者我可以以某种方式“知道”气球还在上升,因此点击一定来自它?

4

1 回答 1

3

的文档TrayIcon似乎暗示单击气球消息可以触发ActionEvent,对于您的情况,这与双击图标本身相同。

您可能需要添加一个鼠标侦听器来触发点击,如果点击事件ActionEvent在某个小段时间内紧随其后,则它是双击,否则它是对正在显示的消息的点击。通过选择足够小的间隔,您应该能够正确区分它们。

于 2012-12-19T19:32:28.807 回答