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


Java SystemTray類代碼示例

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


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

示例1: initSystemTray

import java.awt.SystemTray; //導入依賴的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: initUI

import java.awt.SystemTray; //導入依賴的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

示例3: main

import java.awt.SystemTray; //導入依賴的package包/類
public static void main(String[] args) {
	Util.setNativeLookAndFeel();

	SwingUtilities.invokeLater(new Runnable() {

		public void run() {
			// Check the SystemTray is supported
			if (!SystemTray.isSupported()) {
				System.out.println("SystemTray is not supported");
				System.exit(0);
			} else {
				new Dropzone();
			}
		}
	});
}
 
開發者ID:michaelnetter,項目名稱:dracoon-dropzone,代碼行數:17,代碼來源:Dropzone.java

示例4: processEvent

import java.awt.SystemTray; //導入依賴的package包/類
@Override
protected void processEvent(InboxChangeEvent event) throws IOException {
	// TODO Auto-generated method stub
	if (SystemTray.isSupported()) {
		if(event.getUnreadItemCount() > 0) {
			trayIcon.setImage(this.imageNewMail);
		} else {
			trayIcon.setImage(this.imageNoMail);
		}

		if(OwaNotifier.getInstance().getProps().getProperty("notification.type").contentEquals("system")) {
			trayIcon.displayMessage(event.getEventTitle(), event.getEventText(), MessageType.INFO);
		}
	} else {
		logger.error("System tray not supported!");
	}
	if(event.getUnreadItemCount() > 0) {
		this.setToolTip(event.getUnreadItemCount() + " message(s) non lu");
	} else {
		this.setToolTip("Pas de message non lu");
	}
}
 
開發者ID:OwaNotifier,項目名稱:owa-notifier,代碼行數:23,代碼來源:SystemDesktopProxy.java

示例5: addTrayIconInSystemTray

import java.awt.SystemTray; //導入依賴的package包/類
/** Add tray icon to system tray */
public void addTrayIconInSystemTray() {
	if (SystemTray.isSupported()) {
		setEventListener();
		setMenu();

		try {
			trayIcon.setImageAutoSize(true);
			trayIcon.addActionListener(showListener);
			trayIcon.addMouseListener(mouseListener);
			systemTray.add(trayIcon);
		} catch (AWTException e) {
			e.printStackTrace();
		}

	} else {
		System.err.println("Tray unavailable");
	}
}
 
開發者ID:Team-Sprout,項目名稱:Clipcon-Client,代碼行數:20,代碼來源:TrayIconManager.java

示例6: main

import java.awt.SystemTray; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        System.out.println("SystemTray not supported on the platform." +
            " Marking the test passed.");
    } else {
        if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
            System.err.println(
                "Test can fail on Windows platform\n"+
                "On Windows 7, by default icon hides behind icon pool\n" +
                "Due to which test might fail\n" +
                "Set \"Right mouse click\" -> " +
                "\"Customize notification icons\" -> \"Always show " +
                "all icons and notifications on the taskbar\" true " +
                "to avoid this problem.\nOR change behavior only for " +
                "Java SE tray icon and rerun test.");
        }

        ActionEventTest test = new ActionEventTest();
        test.doTest();
        test.clear();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:ActionEventTest.java

示例7: initializeGUI

import java.awt.SystemTray; //導入依賴的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

示例8: main

import java.awt.SystemTray; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        System.out.println("SystemTray not supported on the platform "
                + "under test. Marking the test passed");
    } else {
        String osName = System.getProperty("os.name").toLowerCase();
        if (osName.startsWith("mac")) {
            isMacOS = true;
        } else if (osName.startsWith("win")) {
            isWinOS = true;
        } else {
            isOelOS = SystemTrayIconHelper.isOel7();
        }
        new TrayIconMouseTest().doTest();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:TrayIconMouseTest.java

示例9: startTray

import java.awt.SystemTray; //導入依賴的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

示例10: formWindowClosing

import java.awt.SystemTray; //導入依賴的package包/類
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    if (trayIcon != null) {
        SystemTray.getSystemTray().remove(trayIcon);
    }
    if (mCurrentAudioMonitor != null) {
        mCurrentAudioMonitor.stopMonitoring();
        mCurrentAudioMonitor = null;
    }
    if (mRemote != null) {
        mRemote.shutdown();
        mRemote = null;
    }
    if (mShortcuts != null) {
        mShortcuts.stop();
    }
}
 
開發者ID:patrickballeux,項目名稱:screenstudio,代碼行數:17,代碼來源:ScreenStudio.java

示例11: TimeTray

import java.awt.SystemTray; //導入依賴的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: Tray

import java.awt.SystemTray; //導入依賴的package包/類
public Tray(MainWindow window) {
	if (tray != null)
		return;
	if (!SystemTray.isSupported()) {
		System.err.println("係統不支持托盤!");
	}
	if (tray == null) {
		tray = SystemTray.getSystemTray();
	}
	if (window == null)
		throw new NullPointerException();
	this.window = window;

	try {
		setTray();
	} catch (Exception e) {
		e.printStackTrace();
	}
	addIcon();
	// window.setVisible(false);
}
 
開發者ID:hafrans,項目名稱:Dannmaku-hime,代碼行數:22,代碼來源:Tray.java

示例13: AWTrayIcon

import java.awt.SystemTray; //導入依賴的package包/類
/**
 * @param frame2
 * @param icon
 * @param title
 * @throws AWTException
 */
public AWTrayIcon(final JFrame frame, final Image icon, final String title) throws AWTException {
    this.frame = frame;
    eventSender = new BasicEventSender<AWTrayIcon>();
    final SystemTray systemTray = SystemTray.getSystemTray();
    /*
     * trayicon message must be set, else windows cannot handle icon right
     * (eg autohide feature)
     */
    trayIcon = new ExtTrayIcon(icon, title);

    trayIcon.addMouseListener(this);
    trayIcon.addTrayMouseListener(this);

    systemTray.add(trayIcon);
}
 
開發者ID:friedlwo,項目名稱:AppWoksUtils,代碼行數:22,代碼來源:AWTrayIcon.java

示例14: initTray

import java.awt.SystemTray; //導入依賴的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.SystemTray; //導入依賴的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.SystemTray類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。