1
我有以下代碼來打開一個窗口通知,但我想要說「點擊這裏」的部分鏈接到一個文本文件。如何將此功能添加到trayicon中?系統托盤圖標,添加一個「點擊這裏」鏈接
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();
}
}
}
我可能是遙遠跟蹤這裏,但是這是我試過(見編輯的代碼)。我只是得到一個致命的錯誤:java.lang.NoSuchMethodError:主要 在異常線程「主」 – cHam 2012-07-25 14:13:39
我想通了,謝謝你的幫助!我更新了上面的代碼,以便將來可以幫助其他人。 – cHam 2012-07-25 14:41:35