本文整理汇总了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);
}
}
}
示例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();
}
示例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);
}
}
示例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));
}
}
});
}
示例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();
}
}
}
示例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));
}
});
}
示例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;
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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);
}
示例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);
}
}
示例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();
}
示例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();
}
}
示例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();
}
}