Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SystemTrayManager
- {
- private SystemTray systemTray = SystemTray.getSystemTray();
- private Toolkit toolkit = Toolkit.getDefaultToolkit();
- private PopupMenu popMenu = new PopupMenu();
- private TrayIcon trayIcon;
- public SystemTrayManager() throws IOException
- {
- this.trayIcon = new TrayIcon(setIconImage("trayIcon.png"), "POD BOT");
- runTray();
- }
- private void runTray()
- {
- if(!SystemTray.isSupported())
- {
- System.out.println("System tray is not supported!");
- return;
- }
- MenuItem exit = new MenuItem("Exit");
- exit.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- popMenu.add(exit);
- trayIcon.setPopupMenu(popMenu);
- try {
- systemTray.add(trayIcon);
- } catch (AWTException e) {
- throw new RuntimeException(e);
- }
- }
- private Image setIconImage(String imagePath)
- {
- return toolkit.getImage(imagePath);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment