removido
(usa Nenhuma)
Enviado em 24/04/2008 - 14:01h
Tive de resolver esse problema semana passada. Fiz uma classe, basta você herdar dela e ser feliz :D
Só tem uma coisa, se não me engano só serve para Java 1.6.
Quaqluer dúvida é só me mandar email. Flw!
package br.com.sulzbach.renato;
import java.awt.AWTException;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
public abstract class TrayIconGui extends JFrame {
private static final long serialVersionUID = 1L;
private Image icone;
private SystemTray tray;
private Toolkit toolkit;
private TrayIcon trayIcon;
private PopupMenu popupMenu;
public TrayIconGui(String titulo, String icone) throws AWTException {
super(titulo);
this.inicializar(icone);
this.configurarGui();
}
private void inicializar(String icone) throws AWTException {
this.tray = SystemTray.getSystemTray();
this.toolkit = Toolkit.getDefaultToolkit();
this.icone = this.toolkit.getImage(icone);
this.setIconImage(this.icone);
this.popupMenu = new PopupMenu();
this.trayIcon = new TrayIcon(this.icone, "Teste", this.popupMenu);
this.trayIcon.setImageAutoSize(true);
this.trayIcon.addActionListener(new TratadorDuploClique(this));
this.tray.add(this.trayIcon);
// this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
protected void adicionarItemMenu(MenuItem mi) {
this.popupMenu.add(mi);
}
protected abstract void configurarGui();
private class TratadorDuploClique implements ActionListener {
private TrayIconGui frame;
public TratadorDuploClique(TrayIconGui frame) {
this.frame = frame;
}
public void actionPerformed(ActionEvent e) {
this.frame.setVisible(!this.frame.isVisible());
}
}
}