【发布时间】:2012-12-19 07:08:25
【问题描述】:
目前在我的(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),或者我必须通过相对时间或其他方式来推断它?或者我能以某种方式“知道”气球还在上升,因此点击肯定来自它?
【问题讨论】:
-
拜托我迷失在 Ruby 中,我们是在谈论 How to Use the System Tray,还是发布 SSCCE,确定双击或鼠标事件到消息没有问题,有几次我回答了 AWT / Swing
-
ok 添加了 jruby 和 java 示例(是的)。我的问题不是如何确定双击,而是更多如何确定气球何时关闭与双击,两者似乎都发送相同的消息......
标签: java awt jruby actionlistener system-tray