gpt4 book ai didi

java - 系统托盘图标,添加 "click here"链接

转载 作者:行者123 更新时间:2023-11-30 04:43:39 24 4
gpt4 key购买 nike

我有以下代码来打开窗口通知,但我希望“单击此处”的部分链接到文本文件。如何将此功能添加到托盘图标中?

public class foundDocs implements ActionListener {


public static void main(String[]args) throws AWTException
{
new foundDocs();
}
foundDocs() throws AWTException
{
SystemTray tray = SystemTray.getSystemTray();
java.awt.Image image = Toolkit.getDefaultToolkit().getImage("tray.gif");
TrayIcon trayIcon = new TrayIcon(image, "Tray Demo");
tray.add(trayIcon);
trayIcon.displayMessage("Found new document associations:", "Click here to view", MessageType.INFO);
trayIcon.addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent arg0)
{
// display the text file in the default app.
try {
Desktop.getDesktop().open(new File("Users.txt"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

最佳答案

Add an ActionListenerTrayIcon。在事件中,使用类似以下内容:

// display the text file in the default app.
Desktop.getDesktop().open(new File("the.txt"));

关于java - 系统托盘图标,添加 "click here"链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11651323/

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