public void setTray() {
   if (SystemTray.isSupported()) {
     Image icon =
         Toolkit.getDefaultToolkit().getImage("C:/.hack3rClient/sprites/cursors/icon.png");
     trayIcon = new TrayIcon(icon, "Vestige-x");
     trayIcon.setImageAutoSize(true);
     try {
       SystemTray tray = SystemTray.getSystemTray();
       tray.add(trayIcon);
       trayIcon.displayMessage(
           "Vestige-x", "Vestige-x has been launched!", TrayIcon.MessageType.INFO);
       PopupMenu menu = new PopupMenu();
       final MenuItem minimizeItem = new MenuItem("Hide Vestige-x");
       MenuItem BLANK = new MenuItem("-");
       MenuItem exitItem = new MenuItem("Quit");
       menu.add(minimizeItem);
       menu.add(BLANK);
       menu.add(exitItem);
       trayIcon.setPopupMenu(menu);
       ActionListener minimizeListener =
           new ActionListener() {
             public void actionPerformed(ActionEvent e) {
               if (frame.isVisible()) {
                 frame.setVisible(false);
                 minimizeItem.setLabel("Show 1# Vestige-x.");
               } else {
                 frame.setVisible(true);
                 minimizeItem.setLabel("Hide 1# Vestige-x.");
               }
             }
           };
       minimizeItem.addActionListener(minimizeListener);
       ActionListener exitListener =
           new ActionListener() {
             public void actionPerformed(ActionEvent e) {
               System.exit(0);
             }
           };
       exitItem.addActionListener(exitListener);
     } catch (AWTException e) {
       System.err.println(e);
     }
   }
 }
示例#2
0
  public void setTray() {
    boolean showTip = false;
    if (tray == null) {
      showTip = true;
      final Image image = Configuration.getImage(Configuration.Paths.Resources.ICON);
      tray = new TrayIcon(image, Configuration.NAME, null);
      tray.setImageAutoSize(true);
      tray.addMouseListener(
          new MouseListener() {
            public void mouseClicked(MouseEvent arg0) {}

            public void mouseEntered(MouseEvent arg0) {}

            public void mouseExited(MouseEvent arg0) {}

            public void mouseReleased(MouseEvent arg0) {}

            public void mousePressed(MouseEvent arg0) {
              SystemTray.getSystemTray().remove(tray);
              setVisible(true);
              lessCpu(false);
            }
          });
    }
    try {
      SystemTray.getSystemTray().add(tray);
      if (showTip) {
        tray.displayMessage(
            Configuration.NAME + " Hidden",
            "Bots are still running in the background.\nClick this icon to restore the window.",
            MessageType.INFO);
      }
    } catch (Exception ignored) {
      log.warning("Unable to hide window");
    }
    setVisible(false);
    lessCpu(true);
  }