Tuesday, July 8, 2014
Trai Icon
import Home.LoginUI;
import java.awt.AWTException;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class TryIcon {
private static JFrame jfame;
private static TrayIcon trayicon;
public static JFrame getJfame() {
return jfame;
}
public static TrayIcon getTrayicon() {
return trayicon;
}
public static void setJfame(final JFrame aJfame) throws AWTException {
jfame = aJfame;
if (trayicon == null) {
setTrayObject();
SystemTray.getSystemTray().add(trayicon);
}
trayicon.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (aJfame.isVisible()) {
jfame.setState(JFrame.MAXIMIZED_BOTH);
jfame.setVisible(true);
jfame.setAlwaysOnTop(true);
} else if (jfame.isVisible()) {
jfame.setState(0);
jfame.setVisible(false);
}
}
});
}
public static void setTrayicon(TrayIcon aTrayicon) {
trayicon = aTrayicon;
}
public static void setTrayObject() {
trayicon = new TrayIcon(new ImageIcon(jfame.getClass().getResource("/Title/star.png")).getImage(), "Create And Develop By", getPopupMenu());
}
private static PopupMenu getPopupMenu() {
PopupMenu menu = new PopupMenu();
MenuItem item = new MenuItem("Logout");
menu.add(item);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(1);
new LoginUI().setVisible(true);
}
});
return menu;
}
public static void main(String[] args) {
try {
TryIcon.setJfame(new JFrame());
TryIcon.getTrayicon().displayMessage("Backup", "your database create backup", MessageType.INFO);
} catch (AWTException ex) {
Logger.getLogger(TryIcon.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment