从方法调用trayIcon.displayMessage()

时间:2013-05-12 17:18:19

标签: java swing actionlistener system-tray trayicon

我知道下面显示气球消息的方式:

something.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        trayIcon.displayMessage("Tray", "Icon", TrayIcon.MessageType.INFO);
    }
});

但有没有办法从方法调用trayIcon.displayMessage()?

void showMsg(){
trayIcon.displayMessage("Tray", "Icon", TrayIcon.MessageType.INFO);
}

不起作用,我不知道下一步该做什么。

这就是我创建trayIcon的方式:

if (SystemTray.isSupported()) {
        SystemTray tray = SystemTray.getSystemTray();
        PopupMenu popup = new PopupMenu();
        windowItem = new MenuItem("Show");
        MenuItem openSettings = new MenuItem("Settings");
        MenuItem areaShot = new MenuItem("sth");
        MenuItem fullShot = new MenuItem("sth");
        MenuItem aboutItem = new MenuItem("About");
        MenuItem exitItem = new MenuItem("Exit");
        popup.add(windowItem);
        popup.add(openSettings);
        popup.addSeparator();
        popup.add(areaShot);
        popup.add(fullShot);
        popup.add(aboutItem);
        popup.add(exitItem);
        trayIcon = new TrayIcon(image, "App", popup);
        trayIcon.setImageAutoSize(true);
}

0 个答案:

没有答案