gpt4 book ai didi

java - 任务托盘通知气球事件?

转载 作者:搜寻专家 更新时间:2023-11-01 04:04:37 25 4
gpt4 key购买 nike

是否有任何可以在任务托盘图标通知气球上调用的java 事件,也就是

trayIcon.displayMessage(title, message, TrayIcon.MessageType.INFO)

就像 dropbox 一样,当我点击气球时,它会将我带到它下载最近文件的文件夹。是否可以使用 java?

最佳答案

通过一些研发,我得到了托盘图标 double click event 当我们点击通知气球时被调用。这就是我要找的。

检查这段代码:

public class Main {
static Image image = Toolkit.getDefaultToolkit().getImage("images/tray.gif");

static TrayIcon trayIcon = new TrayIcon(image, "Tester2");

public static void main(String[] a) throws Exception {
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();

trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("In here");
trayIcon.displayMessage("Tester!", "Some action performed", TrayIcon.MessageType.INFO);
}
});

try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("TrayIcon could not be added.");
}
}
}
}

然后我帮我修改成这样。

private static String location = Roor_Location_Here// contain the root location

然后在双击事件

/*
* Double click action performed *
*/
trayIcon.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Desktop dst = Desktop.getDesktop();
dst.open(new File(location));
/*
* reset the location to root location again.
*/
location = Root_Location_Here // again setting root location
} catch (Exception ex) {
logger.error("------- error with folder opening double click "
+ ex.getMessage());
}
}
});

这是我用来调用通知气球以显示消息的函数:

public static void showNotification(String title, String msg,
String location) {
if (SystemTray.isSupported()) {
trayIcon.displayMessage(title, msg, TrayIcon.MessageType.INFO);
SystemTrayGUI.location = location;// this sets the location that should be opened when balloon is clicked.

}
}

关于java - 任务托盘通知气球事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13989265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com