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


Java TrayIcon類代碼示例

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


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

示例1: initSystemTray

import java.awt.TrayIcon; //導入依賴的package包/類
private static void initSystemTray() {
  // add system tray icon with popup menu
  if (SystemTray.isSupported()) {
    SystemTray tray = SystemTray.getSystemTray();
    PopupMenu menu = new PopupMenu();
    MenuItem exitItem = new MenuItem(Resources.get("menu_exit"));
    exitItem.addActionListener(a -> Game.terminate());
    menu.add(exitItem);

    trayIcon = new TrayIcon(RenderEngine.getImage("pixel-icon-utility.png"), Game.getInfo().toString(), menu);
    trayIcon.setImageAutoSize(true);
    try {
      tray.add(trayIcon);
    } catch (AWTException e) {
      log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
  }
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:19,代碼來源:Program.java

示例2: initialize

import java.awt.TrayIcon; //導入依賴的package包/類
/**
 * Starts the TrayIcon, if this is supported. If not, it should start a
 * simple JDialog, doing the same as independent Window.
 */
private void initialize() {

	switch (this.getTrayIconUsage()) {
	case TrayIcon:
		try {
			// --- System-Tray is supported ---------------------
			this.getSystemTray().add(this.getTrayIcon(true));
			
		} catch (AWTException e) {
			System.err.println("TrayIcon supported, but could not be added. => Use TrayDialog instead !");
			this.getAgentGUITrayDialog(true).setVisible(true);			
		}
		break;
		
	case TrayDialog:
		this.getAgentGUITrayDialog(true).setVisible(true);
		break;

	default:
		break;
	}
	
	// --- Refresh tray icon ------------------------------------
	this.getAgentGUITrayPopUp().refreshView();
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:30,代碼來源:AgentGUITrayIcon.java

示例3: initUI

import java.awt.TrayIcon; //導入依賴的package包/類
/**
 * Init Swing UI
 */
private void initUI() {
	URL url = null;
	if (ConfigIO.getInstance().isUseDarkIcon()) {
		url = Dropzone.class.getResource("/images/sds_logo_dark.png");
	} else {
		url = Dropzone.class.getResource("/images/sds_logo_light.png");

	}
	if (Util.getOSType() == OSType.MACOS) {

	}

	trayIcon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(url), I18n.get("tray.appname"),
			new TrayPopupMenu());
	trayIcon.setImageAutoSize(true);

	final SystemTray tray = SystemTray.getSystemTray();
	try {
		tray.add(trayIcon);
	} catch (AWTException e) {
		LOG.error("TrayIcon could not be added.");
		System.exit(1);
	}
}
 
開發者ID:michaelnetter,項目名稱:dracoon-dropzone,代碼行數:28,代碼來源:Dropzone.java

示例4: showPopupMenu

import java.awt.TrayIcon; //導入依賴的package包/類
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:WTrayIconPeer.java

示例5: updateNativeImage

import java.awt.TrayIcon; //導入依賴的package包/類
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:WTrayIconPeer.java

示例6: showPopupMenu

import java.awt.TrayIcon; //導入依賴的package包/類
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, () -> {
        PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
        if (popup != newPopup) {
            if (popup != null) {
                popupParent.remove(popup);
            }
            if (newPopup != null) {
                popupParent.add(newPopup);
            }
            popup = newPopup;
        }
        if (popup != null) {
            WPopupMenuPeer peer = AWTAccessor.getMenuComponentAccessor()
                                             .getPeer(popup);
            peer.show(popupParent, new Point(x, y));
        }
    });
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:WTrayIconPeer.java

示例7: createPopupMenu

import java.awt.TrayIcon; //導入依賴的package包/類
private PopupMenu createPopupMenu(final TrayIcon trayIcon,
        final int menuCount) {

    final PopupMenu trayIconPopupMenu = new PopupMenu();

    for (int i = 1; i <= menuCount; ++i) {
        final MenuItem popupMenuItem = new MenuItem("MenuItem_" + i);

        popupMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent ae) {
                trayIcon.setPopupMenu(createPopupMenu(trayIcon,
                        menuCount + 1));
            }
        });

        trayIconPopupMenu.add(popupMenuItem);
    }

    return trayIconPopupMenu;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:UpdatePopupMenu.java

示例8: initializeGUI

import java.awt.TrayIcon; //導入依賴的package包/類
private void initializeGUI() {

        icon = new TrayIcon(
            new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), "ti");
        icon.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                actionPerformed = true;
                int md = ae.getModifiers();
                int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
                        | ActionEvent.SHIFT_MASK;

                if ((md & expectedMask) != expectedMask) {
                    clear();
                    throw new RuntimeException("Action Event modifiers are not"
                        + " set correctly.");
                }
            }
        });

        try {
            SystemTray.getSystemTray().add(icon);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:ActionEventTest.java

示例9: showMessageTray

import java.awt.TrayIcon; //導入依賴的package包/類
/**
 * Показать сообщение в системном трее
 *
 * @param message текст сообщения
 * @param type тип сообщения
 */
synchronized public void showMessageTray(String caption, String message, MessageType type) {
    TrayIcon.MessageType t = TrayIcon.MessageType.NONE;
    switch (type) {
        case ERROR: {
            t = TrayIcon.MessageType.ERROR;
            break;
        }
        case WARNING: {
            t = TrayIcon.MessageType.WARNING;
            break;
        }
        case INFO: {
            t = TrayIcon.MessageType.INFO;
            break;
        }
    }
    trayIcon.displayMessage(caption, message, t);
}
 
開發者ID:bcgov,項目名稱:sbc-qsystem,代碼行數:25,代碼來源:QTray.java

示例10: startTray

import java.awt.TrayIcon; //導入依賴的package包/類
private static void startTray()
{
	SystemTray tray = SystemTray.getSystemTray();
	int w = 80;
	int[] pix = new int[w * w];
	for (int i = 0; i < w * w; i++)
		pix[i] = (int) (Math.random() * 255);
	ImageProducer producer = new MemoryImageSource(w, w, pix, 0, w);
	Image image = Toolkit.getDefaultToolkit().createImage(producer);
	TrayIcon trayIcon = new TrayIcon(image);
	trayIcon.setImageAutoSize(true);
	startWindow();
	try
	{
		tray.add(trayIcon);
		System.out.println("installed tray");
	}
	catch (AWTException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:yajsw,項目名稱:yajsw,代碼行數:24,代碼來源:HelloWorld.java

示例11: TimeTray

import java.awt.TrayIcon; //導入依賴的package包/類
/**
 * TimeTray Constructor
 */
public TimeTray() {
    // retrieve iconSize of SystemTray
    SystemTray systemTray = SystemTray.getSystemTray();
    iconSize = systemTray.getTrayIconSize();

    // set presets
    presets = new Presets(iconSize.height);

    calendar = Calendar.getInstance();

    // create TrayIcon according to iconSize
    trayIcon = new TrayIcon(getTrayImage(), "TimeTray", menu);
    try {
        systemTray.add(trayIcon);
    } catch (AWTException ex) {
        ex.printStackTrace();
    }

    // run thread and set timer tooltip to update every second
    run();

    Timer timer = new Timer();
    timer.schedule(this, 1000, 1000);
}
 
開發者ID:otacke,項目名稱:timetray,代碼行數:28,代碼來源:TimeTray.java

示例12: sendNotification

import java.awt.TrayIcon; //導入依賴的package包/類
private void sendNotification(
	final String title,
	final String message,
	final TrayIcon.MessageType type,
	final String subtitle)
{
	final String escapedTitle = SHELL_ESCAPE.escape(title);
	final String escapedMessage = SHELL_ESCAPE.escape(message);
	final String escapedSubtitle = subtitle != null ? SHELL_ESCAPE.escape(subtitle) : null;

	switch (DETECTED_OS)
	{
		case Linux:
			sendLinuxNotification(escapedTitle, escapedMessage, type);
			break;
		case MacOS:
			sendMacNotification(escapedTitle, escapedMessage, escapedSubtitle);
			break;
		default:
			sendTrayNotification(title, message, type);
	}
}
 
開發者ID:runelite,項目名稱:runelite,代碼行數:23,代碼來源:Notifier.java

示例13: startProcess

import java.awt.TrayIcon; //導入依賴的package包/類
private void startProcess() {

Thread thread = new Thread(new Runnable() {

 @Override public void run() {
 Preferences prefs = Preferences.userNodeForPackage(duckdns.class);

 // first start message (on empty settings)
 if ((prefs.get("domain", "").length() < 1) || (prefs.get("token", "").length() < 1)) {
 processTrayIcon.displayMessage(DuckDNSVersion, "Right click on the tray icon to change the settings!", TrayIcon.MessageType.INFO);
 }

 Timer timer = new Timer("Repeater");
 MyTask t = new MyTask();
 timer.schedule(t, 0, 1000);

 timercount = (Integer.parseInt(prefs.get("refresh", "5")) * 60);

 }
});

thread.start();
}
 
開發者ID:JozefJarosciak,項目名稱:DuckDNSClient,代碼行數:24,代碼來源:duckdns.java

示例14: 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

示例15: 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


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