本文整理匯總了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();
}
}
示例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();
}
}
示例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);
}
}
}
}
示例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");
}
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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());
}
}
示例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;
}
示例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);
}
示例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();
}
}
示例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);
}
}