當前位置: 首頁>>代碼示例>>Java>>正文


Java TrayIcon.addMouseListener方法代碼示例

本文整理匯總了Java中java.awt.TrayIcon.addMouseListener方法的典型用法代碼示例。如果您正苦於以下問題:Java TrayIcon.addMouseListener方法的具體用法?Java TrayIcon.addMouseListener怎麽用?Java TrayIcon.addMouseListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.TrayIcon的用法示例。


在下文中一共展示了TrayIcon.addMouseListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initTray

import java.awt.TrayIcon; //導入方法依賴的package包/類
private void initTray() {
	final SystemTray systemTray = SystemTray.getSystemTray();
	final TrayIcon trayIcon = new TrayIcon(getImage("icon.gif"), "Deskshare is running");
	trayIcon.setImageAutoSize(true); // Autosize icon base on space
									 // available on tray
	MouseAdapter mouseAdapter = new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent evt) {
			// This will display small popup message from System Tray
			trayIcon.displayMessage("BigMarker Deskshare", "This is an info message", TrayIcon.MessageType.INFO);
			if (!app.isVisible()) {
				app.setVisible(true);
			}
		}
	};
	trayIcon.addMouseListener(mouseAdapter);
	try {
		systemTray.add(trayIcon);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:BigMarker,項目名稱:deskshare-public,代碼行數:23,代碼來源:SmallUI.java

示例2: initTray

import java.awt.TrayIcon; //導入方法依賴的package包/類
private void initTray() {
	final SystemTray systemTray = SystemTray.getSystemTray();
	final TrayIcon trayIcon = new TrayIcon(getImage("icon.gif"), "Deskshare is running");
	trayIcon.setImageAutoSize(true); // Autosize icon base on space available on tray
	MouseAdapter mouseAdapter = new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent evt) {
			System.out.println("icon clicked: " + evt.getClickCount());
			// This will display small popup message from System Tray
			trayIcon.displayMessage("BigMarker Deskshare", "This is an info message", TrayIcon.MessageType.INFO);
			if (!app.isVisible()) {
				app.setVisible(true);
			}
		}
	};
	trayIcon.addMouseListener(mouseAdapter);
	try {
		systemTray.add(trayIcon);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:BigMarker,項目名稱:deskshare-public,代碼行數:23,代碼來源:DebugUI.java

示例3: init

import java.awt.TrayIcon; //導入方法依賴的package包/類
/**
 * Initializes the tray
 */
public void init() {

	if (SystemTray.isSupported()) {

		SystemTray tray = SystemTray.getSystemTray();

		if (tray.getTrayIcons().length == 0) {

			String iconFileName = resources.getImagePath() + File.separator
					+ "MidiAutomatorIcon16.png";
			image = Toolkit.getDefaultToolkit().getImage(iconFileName);
			trayPopupMenu.init();
			trayIcon = new TrayIcon(image, NAME);
			trayIcon.addMouseListener(trayMouseListener);

			try {
				tray.add(trayIcon);
			} catch (AWTException e) {
				log.error("Error on adding tray icon.", e);
			}
		}
	}
}
 
開發者ID:aguelle,項目名稱:MIDI-Automator,代碼行數:27,代碼來源:Tray.java

示例4: createAndShowGui

import java.awt.TrayIcon; //導入方法依賴的package包/類
private static void createAndShowGui() {
    JDialog dialog = createDialog();

    CloseDialogListener closeDialogListener = new CloseDialogListener(dialog);
    dialog.addWindowFocusListener(closeDialogListener);

    JPopupMenu systemTrayPopupMenu = buildMenu();
    systemTrayPopupMenu.addPopupMenuListener(closeDialogListener);

    TrayIcon trayIcon = new TrayIcon(getTrayIconImage());
    trayIcon.addMouseListener(new ShowTrayMenuListener(systemTrayPopupMenu, dialog));

    try {
        SystemTray.getSystemTray().add(trayIcon);
    } catch (AWTException e) {
        throw new IllegalStateException("Failed to add tray icon");
    }

}
 
開發者ID:apixandru,項目名稱:JVShot,代碼行數:20,代碼來源:Main.java

示例5: SysTrayIcon

import java.awt.TrayIcon; //導入方法依賴的package包/類
public SysTrayIcon(JDesktopAgent frame, String tooltip) {
    Translate translate = Translate.getTranslate();
    if (SystemTray.isSupported()) {
        Image image = Toolkit.getDefaultToolkit().getImage("icon.png");

        PopupMenu popup = new PopupMenu();
        popup.add(new RestoreMenuItem(frame, translate.backgroundRestore()));
        popup.addSeparator();
        popup.add(new AboutMenuItem(translate.about()));
        popup.addSeparator();
        popup.add(new ExitMenuItem(translate.exit()));

        TrayIcon trayIcon = new TrayIcon(image, tooltip, popup);
        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new IconListener(frame));

        try {
            SystemTray.getSystemTray().add(trayIcon);
        } catch (AWTException e) {
            new SysTrayForm(frame).setVisible(true);
        }
    } else {
        new SysTrayForm(frame).setVisible(true);
    }

}
 
開發者ID:gems-uff,項目名稱:oceano,代碼行數:27,代碼來源:SysTrayIcon.java

示例6: create

import java.awt.TrayIcon; //導入方法依賴的package包/類
public static boolean create()
{
	menu = new Menu();
	try
	{
		icon = new TrayIcon(Constants.TRAY_ICON, "UploadR", menu);
		icon.addMouseListener(menu.getItemHandler());
		SystemTray.getSystemTray().add(icon);
		icon.setToolTip("UploadR");
		return true;
	}
	catch(AWTException e)
	{
		return false;
	}
}
 
開發者ID:Hual,項目名稱:UploadR,代碼行數:17,代碼來源:MenuTrayIcon.java

示例7: hideToTray

import java.awt.TrayIcon; //導入方法依賴的package包/類
private void hideToTray() {
  if (!isInTray) {
    SystemTray tray = SystemTray.getSystemTray();
    String iconPath = tray.getTrayIconSize().height > 16 ? TRAY_ICON : TRAY_SMALL_ICON;
    URL iconUrl = JLanguageTool.getDataBroker().getFromResourceDirAsUrl(iconPath);
    Image img = Toolkit.getDefaultToolkit().getImage(iconUrl);
    PopupMenu popup = makePopupMenu();
    try {
      trayIcon = new TrayIcon(img, TRAY_TOOLTIP, popup);
      trayIcon.addMouseListener(new TrayActionListener());
      setTrayIcon();
      tray.add(trayIcon);
    } catch (AWTException e1) {
      Tools.showError(e1);
    }
  }
  isInTray = true;
  frame.setVisible(false);
}
 
開發者ID:languagetool-org,項目名稱:languagetool,代碼行數:20,代碼來源:Main.java

示例8: setupTrayIcon

import java.awt.TrayIcon; //導入方法依賴的package包/類
private TrayIcon setupTrayIcon()
{
	if (!SystemTray.isSupported())
	{
		return null;
	}

	SystemTray systemTray = SystemTray.getSystemTray();
	TrayIcon trayIcon = new TrayIcon(ICON, properties.getTitle());
	trayIcon.setImageAutoSize(true);

	try
	{
		systemTray.add(trayIcon);
	}
	catch (AWTException ex)
	{
		log.debug("Unable to add system tray icon", ex);
		return trayIcon;
	}

	// bring to front when tray icon is clicked
	trayIcon.addMouseListener(new MouseAdapter()
	{
		@Override
		public void mouseClicked(MouseEvent e)
		{
			setVisible(true);
			setState(Frame.NORMAL); // unminimize
		}
	});

	return trayIcon;
}
 
開發者ID:runelite,項目名稱:runelite,代碼行數:35,代碼來源:ClientUI.java

示例9: initialize

import java.awt.TrayIcon; //導入方法依賴的package包/類
public static void initialize() throws Exception {		
	if (SystemTray.isSupported()) {
	    SystemTray tray = SystemTray.getSystemTray();

	    Image image = IconUtils.getIcon("icon-16x16").getImage();
	
	    icon = new TrayIcon(image, "gscrot");
	    icon.addMouseListener(new MouseAdapter() {
	    	public void mouseClicked(MouseEvent e)  {
	    		if (e.getClickCount() == 2 && !e.isConsumed()) {
					e.consume();
					MainFrame frame = MainFrame.INSTANCE;
					if (frame.getState() == Frame.ICONIFIED) {
						frame.setState(Frame.NORMAL);
					} else {
						frame.setState(Frame.ICONIFIED);
					}
				} else if (SwingUtilities.isRightMouseButton(e)) {
					 GlobalPopupMenu.getPopupMenu().show(null, e.getXOnScreen(), e.getYOnScreen());
				}
	    	}
	    });
	    
	    statusIcon = new StatusIcon(Mode.IMAGES, icon);
	    
	    for (int i = 1; i <= 8; i++) {
	    	statusIcon.getIcons().add(IconUtils.getIcon("load" + i).getImage());
	    }
	    
	    tray.add(icon);
	}
}
 
開發者ID:gscrot,項目名稱:gscrot,代碼行數:33,代碼來源:TrayIconHelper.java

示例10: initTray

import java.awt.TrayIcon; //導入方法依賴的package包/類
private void initTray() {
	// get the system tray
	SystemTray systemTray = SystemTray.getSystemTray();
	// create a "hidden" frame for the popup menu
	final Frame frame = new Frame("");
       frame.setUndecorated(true);
	try {
        // instance the icon
        BufferedImage icon = ImageIO.read(SimpleUI.class.getResource("/icon_16x16x32.png"));
		final TrayIcon trayIcon = new TrayIcon(new ImageIcon(icon).getImage(), Main.getString("msg.systemtray"));
		trayIcon.setImageAutoSize(true); // Autosize icon base on space available on tray
		final PopupMenu menu = createPopupMenu();
        trayIcon.setPopupMenu(menu);
		trayIcon.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent evt) {
				System.out.println("icon clicked: " + evt.getClickCount());
				// dont display the menu if the screen selection ui (this jframe) is showing
				if (!isVisible()) {
		            frame.setVisible(true);
					frame.add(menu);
					menu.show(frame, evt.getXOnScreen(), evt.getYOnScreen());
				}
			}
		});
		frame.setResizable(false);
		systemTray.add(trayIcon);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:BigMarker,項目名稱:deskshare-public,代碼行數:32,代碼來源:SimpleUI.java

示例11: initTray

import java.awt.TrayIcon; //導入方法依賴的package包/類
private void initTray()
  {
  	Image image = new ImageIcon(WindowUtil.class.getResource("icon.png")).getImage();

  	mTrayIcon = new TrayIcon(image, mTrayTitle, createPopupMenu(BEFORE_LOGIN_STATE));
  	mTrayIcon.setImageAutoSize(true);
  	mTrayIcon.addMouseListener(new java.awt.event.MouseAdapter() {
  		
  		public void mousePressed(java.awt.event.MouseEvent e) {			
  			log.debug("mousePressed()");   			
  			int state = 0;    			
		currentFrame = UISharedData.getInstance().getCurrentFrame();				
		
		if(currentFrame == null) return;				
		if(currentFrame.getClass().equals(JFrmLogin.class)) {					
			state = BEFORE_LOGIN_STATE;					
		} else {					
			state = AFTER_LOGIN_STATE;
		}

		if(SwingUtilities.isRightMouseButton(e)) { 					
			mTrayIcon.setPopupMenu(createPopupMenu(state));			
		}

		if(e.getClickCount() >= DOUBLE_CLICK && !e.isConsumed()){ 				
			currentFrame.setVisible(true);
		}		
	}
});

  	try 
  	{
	mSystemTray.add(mTrayIcon);
} 
  	catch (AWTException e1) 
  	{
  		log.warn(e1.getMessage());
}
  }
 
開發者ID:spdx,項目名稱:ATTIC-osit,代碼行數:40,代碼來源:JTrayIconApp.java

示例12: initSystemTray

import java.awt.TrayIcon; //導入方法依賴的package包/類
/**
 * This method inits the system tray. if supported, the program's window
 * does not deiconfy/minimize to the taskbar, but hides and displays an icon
 * in the system tray instead.
 */
private void initSystemTray() {
    // if systemtray is not supported, leave method
    if (!SystemTray.isSupported()) {
        return;
    }
    // create tray-icon with tooltip
    trayIcon = new TrayIcon((new ImageIcon(org.jdesktop.application.Application.getInstance(de.danielluedecke.zettelkasten.ZettelkastenApp.class).getClass().getResource("/de/danielluedecke/zettelkasten/resources/icons/zkn3_16x16.png"), "Zettelkasten")).getImage());
    // retrieve system tray
    tray = SystemTray.getSystemTray();
    // try to add the tray icon to the systray
    try {
        tray.add(trayIcon);
    } catch (AWTException e) {
        Constants.zknlogger.log(Level.WARNING, "Tray Icon could not be added.");
        return;
    }
    // if tray icon was successfully added, add tooltip
    trayIcon.setToolTip("Zettelkasten");
    // and mouse listener, so the window will be restored when the user clicks on the tray icon
    trayIcon.addMouseListener(new java.awt.event.MouseAdapter() {
        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            // set main frame visible
            getFrame().setVisible(true);
            // restore frame state to normal state
            getFrame().setExtendedState(java.awt.Frame.NORMAL);
            // if we have a tray icon, remove it
            if (tray != null) {
                // clear popup menu
                trayIcon.setPopupMenu(null);
                // remove tray icon
                tray.remove(trayIcon);
            }
            // and say that tray icon is currently not installed
            trayIconInstalled = false;
        }
    });
    trayIconInstalled = true;
}
 
開發者ID:sjPlot,項目名稱:Zettelkasten,代碼行數:45,代碼來源:ZettelkastenView.java

示例13: setTrayIcon

import java.awt.TrayIcon; //導入方法依賴的package包/類
public void setTrayIcon(Image i_16x16, Image i_22x22, String tt, PopupMenu pm) throws Exception {
	boolean autoSize = false;
	Image i = null;
	Dimension d = tray.getTrayIconSize();
	if (d.height == 16 && d.width == 16)
	{
		i = i_16x16;
		//System.out.println ("Tray 16x16 picked");
		autoSize = true;
	}
	else
	{
		i = i_22x22;
		//System.out.println ("Tray 22x22 picked");
		autoSize = true;
	}

	trayIcon = new TrayIcon (i, tt);
	trayIcon.addMouseListener(this);
	trayIcon.setImageAutoSize(autoSize);

	if (pm != null)
		trayIcon.setPopupMenu(pm);

	tray.add(trayIcon);

	//System.out.println ("Tray real width=" + trayIcon.getSize().width + " height=" + trayIcon.getSize().height);

}
 
開發者ID:woboq,項目名稱:p300,代碼行數:30,代碼來源:GuruztrayManagerImplementation.java

示例14: setupTrayIcon

import java.awt.TrayIcon; //導入方法依賴的package包/類
private void setupTrayIcon() {
trayAvailable = true;

tray = SystemTray.getSystemTray();

trayIcon = new TrayIcon(getTrayIconImage(ICON_LOADER), lang.translationForKey("tray.message.loading"), null);
trayIcon.setImageAutoSize(true);
trayIcon.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
	if (status != null) {
	    status.showInfo(new Point(e.getX(), e.getY()));
	}
    }
});

try {
    tray.add(trayIcon);
} catch (AWTException ex) {
    logger.error("TrayIcon could not be added to the system tray.", ex);

    // tray and trayIcon are not needed anymore
    tray = null;
    trayIcon = null;
    setupFrame();
}
   }
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:28,代碼來源:AppTray.java

示例15: toSystray

import java.awt.TrayIcon; //導入方法依賴的package包/類
/**
 * Makes the entire program invisible and adds an icon to 
 * the systray. DOES NOT EXIT!
 */
public void toSystray() {
    logger.debug("minimize");
    try {
        if (!SystemTray.isSupported())
            throw new Exception();
        atSystray = true;
        setVisible(false);
        //calendar.save();

        /* Tray icon title */
        String title = "Kalender - " + new Date().dateToString(false) + "\n* 1 Klick: Statusinformation abrufen\n* Doppelklick: Kalender hervorholen\n* rechte Maustaste: Men�";
        
        /*
         * Create tray icon and popup menu
         */
        trayIcon = new TrayIcon(cal16, title, new TrayIconMenu(this));
        trayIcon.addMouseListener(this);
        trayIcon.setImageAutoSize(true);
        boolean firstSystrayMove = false;
        if (systray == null) {
            systray = SystemTray.getSystemTray();
            firstSystrayMove = true;
        }

        systray.add(trayIcon);
        if (calendar.isFirstStartup() && firstSystrayMove)
            trayIcon.displayMessage("Kalender:",
                    "Der Kalender befindet sich jetzt hier.\nDoppelklicken zum Hervorholen oder rechte Maustaste zum Beenden.",
                    TrayIcon.MessageType.INFO);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, 
                "Das Betriebssystem unterst�tzt keinen Systray!\nDer Kalender wird nun beendet...");
        /* call shutdown hook */
        System.exit(0);
    }
}
 
開發者ID:devypt,項目名稱:Kalender,代碼行數:41,代碼來源:CalendarFrame.java


注:本文中的java.awt.TrayIcon.addMouseListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。