1

ウィンドウ通知を開く次のコードがありますが、「ここをクリック」という部分をテキスト ファイルにリンクする必要があります。この機能をトレイアイコンに追加するにはどうすればよいですか?

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();
    } 

}

}

4

1 に答える 1

2

に を追加ActionListenerTrayIconます。イベントでは、次のようなものを使用します。

// display the text file in the default app.
Desktop.getDesktop().open(new File("the.txt"));
于 2012-07-25T14:06:01.200 に答える