List of usage examples for java.awt MenuItem addActionListener
public synchronized void addActionListener(ActionListener l)
From source file:de.mycrobase.jcloudapp.Main.java
public void run() { if (!SystemTray.isSupported()) { showErrorDialog("SystemTray is unsupported!"); exit();/*from w ww . j a va 2 s. c om*/ } icon = new TrayIcon(ImageNormal); icon.setImageAutoSize(true); icon.setToolTip("JCloudApp"); icon.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!working) { working = true; doUploadClipboard(); working = false; } } }); MenuItem screen = new MenuItem("Take Screenshot"); screen.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!working) { working = true; doScreenshot(); working = false; } } }); MenuItem uploadClip = new MenuItem("Upload from Clipboard"); uploadClip.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!working) { working = true; doUploadClipboard(); working = false; } } }); MenuItem upload = new MenuItem("Upload File..."); upload.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!working) { working = true; doUploadFile(); working = false; } } }); MenuItem about = new MenuItem("About"); about.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doAbout(); } }); MenuItem quit = new MenuItem("Quit"); quit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doQuit(); } }); PopupMenu popupMenu = new PopupMenu(); popupMenu.add(screen); popupMenu.add(uploadClip); popupMenu.add(upload); popupMenu.add(about); popupMenu.addSeparator(); popupMenu.add(quit); icon.setPopupMenu(popupMenu); try { SystemTray.getSystemTray().add(icon); } catch (AWTException ex) { showErrorDialog("No SystemTray found!\n" + ex); exit(); } }
From source file:ListenerReuse.java
public ListenerReuse() { Button b = new Button("Save"); add(b);/* w w w . java 2 s.c o m*/ MenuBar mb = new MenuBar(); setMenuBar(mb); Menu fm = new Menu("File"); mb.add(fm); MenuItem mi = new MenuItem("Save"); fm.add(mi); // Construct the ActionListener, and keep a reference to it. ActionListener saver = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Saving your file..."); // In real life we would call the doSave() method // in the main class, something like this: // mainProg.doSave(); } }; // Register the actionListener with the Button b.addActionListener(saver); // And now register the same actionListener with the MenuItem mi.addActionListener(saver); pack(); }
From source file:com.darkenedsky.reddit.traders.RedditTraders.java
/** * Construct a new RedditTraders instance. * /*from w ww . j a va2 s. co m*/ * */ public RedditTraders() { // Load XML configuration file, connect to DB and connect to Reddit API try { config = new Configuration(); addListener(new Help(this)); addListener(new About(this)); addListener(new Confirm(this)); addListener(new Activate(this)); listeners.put("DEACTIVATE", new Activate(this)); addListener(new CountAllSubs(this)); addListener(new ModHelp(this)); addListener(new AcceptModInvite(this)); addListener(new Install(this)); addListener(new Cake(this)); addListener(new Trade(this)); addListener(new TopTraders(this, "TOP20", 20)); addListener(new Lookup(this)); addListener(new SetLegacy(this)); addListener(new SetTextFlair(this)); addListener(new ViewFlair(this)); addListener(new Resolve(this)); listeners.put("BLAME", new Resolve(this)); listeners.put("CLOSE", new Resolve(this)); addListener(new SetFlair(this)); listeners.put("REMOVEFLAIR", new SetFlair(this)); addListener(new SetModFlair(this)); listeners.put("REMOVEMODFLAIR", new SetModFlair(this)); addListener(new SetBlameBan(this)); addListener(new SetList(this)); listeners.put("SETHAVELIST", new SetList(this)); addListener(new GetList(this)); listeners.put("HAVELIST", new GetList(this)); addListener(new SetAccountAgeRequirement(this)); addListener(new SetVerifiedEmail(this)); addListener(new Undo(this)); addListener(new LastTrades(this, "LAST10", 10)); addListener(new SetCheckBan(this)); addListener(new SetDaysBetween(this)); // Build a system tray icon SystemTray tray = SystemTray.getSystemTray(); PopupMenu popup = new PopupMenu(); MenuItem todaysLog = new MenuItem("Today's Log"); todaysLog.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { new TextFrame("logs/RedditTraders.log").setVisible(true); } catch (Exception e1) { LOG.error(e1); } } }); popup.add(todaysLog); MenuItem exit = new MenuItem("Exit"); ActionListener exitListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }; exit.addActionListener(exitListener); popup.add(exit); Image image = Toolkit.getDefaultToolkit().getImage("reddit.png"); TrayIcon trayIcon = new TrayIcon(image, "RedditTraders " + config.getVersion(), popup); trayIcon.setImageAutoSize(true); tray.add(trayIcon); LOG.debug("RedditTraders launched OK."); } catch (Exception x) { x.printStackTrace(); System.exit(0); } }
From source file:vn.topmedia.monitor.form.MDIMain.java
public void goToTray() { if (SystemTray.isSupported()) { SystemTray tray = SystemTray.getSystemTray(); normal = Toolkit.getDefaultToolkit().getImage("normal.gif"); MouseListener mouseListener = new MouseListener() { public void mouseClicked(MouseEvent e) { // System.out.println("Tray Icon - Mouse clicked!"); }//from ww w. j a v a 2 s .c o m public void mouseEntered(MouseEvent e) { // System.out.println("Tray Icon - Mouse entered!"); } public void mouseExited(MouseEvent e) { // System.out.println("Tray Icon - Mouse exited!"); } public void mousePressed(MouseEvent e) { // System.out.println("Tray Icon - Mouse pressed!"); showMonitor(0); } public void mouseReleased(MouseEvent e) { // System.out.println("Tray Icon - Mouse released!"); } }; ActionListener exitListener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Exiting..."); mnuItmExit.doClick(); } }; ActionListener showMonitorListener = new ActionListener() { public void actionPerformed(ActionEvent e) { showMonitor(2); } }; popup = new PopupMenu(); //--------------------------- MenuItem showItem; showItem = new MenuItem("Show"); showItem.addActionListener(showMonitorListener); popup.add(showItem); //----------------- popup.addSeparator(); //------------------------ MenuItem defaultItem = new MenuItem("Exit"); defaultItem.addActionListener(exitListener); popup.add(defaultItem); //------------------------ trayIcon = new TrayIcon(normal, "ExMonitor 1.3", popup); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { showMonitor(2); } }; trayIcon.setImageAutoSize(true); trayIcon.addActionListener(actionListener); trayIcon.addMouseListener(mouseListener); try { tray.add(trayIcon); } catch (AWTException e) { System.err.println("TrayIcon could not be added."); } } else { // System Tray is not supported } }
From source file:de.codesourcery.gittimelapse.MyFrame.java
private MenuBar createMenuBar() { final MenuBar menuBar = new MenuBar(); final Menu menu = new Menu("File"); final MenuItem item1 = new MenuItem("About..."); item1.addActionListener(new ActionListener() { @Override// w ww .j a v a2s . co m public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "GIT timelapse V0.1\n\n(C) 2014 tobias.gierke@code-sourcery.de", "About", JOptionPane.PLAIN_MESSAGE); } }); menu.add(item1); final MenuItem item2 = new MenuItem("Quit"); item2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); menu.add(item2); menuBar.add(menu); return menuBar; }
From source file:org.shelloid.vpt.agent.App.java
private void setupSystemTray() { if (SystemTray.isSupported()) { try {//from w w w .j a v a 2 s .c o m final ConfigForm configForm = new ConfigForm(false); final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("/images/logo.jpg"), "Shelloid VPT Agent"); tray = SystemTray.getSystemTray(); MenuItem authenticateItem = new MenuItem("Configure Authentication"); MenuItem aboutItem = new MenuItem("About Shelloid VPT Agent"); MenuItem exitItem = new MenuItem("Exit"); trayIcon.setPopupMenu(popup); tray.add(trayIcon); authenticateItem.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { configForm.setVisible(true); } }); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "Shelloid VPT Agent.\nVersion : " + getVersion() + "\n\n(c) 2014 Shelloid LLC. \nhttps://www.shelloid.com", "Shelloid VPT Client", JOptionPane.INFORMATION_MESSAGE); } }); exitItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(null, "Are you sure to exit Shelloid VPT Agent?", "Shelloid VPT Agent", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { shuttingDown = true; closeAllConnections(); System.exit(0); } } }); popup.add(authenticateItem); popup.add(aboutItem); popup.addSeparator(); popup.add(exitItem); } catch (Exception ex) { Platform.shelloidLogger.warn("System Tray Error: ", ex); } } else { System.out.println("System tray is not supported"); } }
From source file:org.exist.launcher.Launcher.java
private PopupMenu createMenu() { final PopupMenu popup = new PopupMenu(); startItem = new MenuItem("Start server"); popup.add(startItem);//from ww w. ja v a 2 s . co m startItem.addActionListener(actionEvent -> { if (jetty.isPresent()) { jetty.ifPresent(server -> { if (server.isStarted()) { showTrayMessage("Server already started", TrayIcon.MessageType.WARNING); } else { server.run(new String[] { jettyConfig.toAbsolutePath().toString() }, null); if (server.isStarted()) { showTrayMessage("eXist-db server running on port " + server.getPrimaryPort(), TrayIcon.MessageType.INFO); } } setServiceState(); }); } else if (runningAsService.isPresent()) { showTrayMessage("Starting the eXistdb service. Please wait...", TrayIcon.MessageType.INFO); if (runningAsService.get().start()) { showTrayMessage("eXistdb service started", TrayIcon.MessageType.INFO); } else { showTrayMessage("Starting eXistdb service failed", TrayIcon.MessageType.ERROR); } setServiceState(); } }); stopItem = new MenuItem("Stop server"); popup.add(stopItem); stopItem.addActionListener(actionEvent -> { if (jetty.isPresent()) { jetty.get().shutdown(); setServiceState(); showTrayMessage("eXist-db stopped", TrayIcon.MessageType.INFO); } else if (runningAsService.isPresent()) { if (runningAsService.get().stop()) { showTrayMessage("eXistdb service stopped", TrayIcon.MessageType.INFO); } else { showTrayMessage("Stopping eXistdb service failed", TrayIcon.MessageType.ERROR); } setServiceState(); } }); popup.addSeparator(); final MenuItem configItem = new MenuItem("System Configuration"); popup.add(configItem); configItem.addActionListener(e -> EventQueue.invokeLater(() -> { configDialog.open(false); configDialog.toFront(); configDialog.repaint(); configDialog.requestFocus(); })); if (SystemUtils.IS_OS_WINDOWS) { canUseServices = true; } else { isRoot((root) -> canUseServices = root); } final String requiresRootMsg; if (canUseServices) { requiresRootMsg = ""; } else { requiresRootMsg = " (requires root)"; } installServiceItem = new MenuItem("Install as service" + requiresRootMsg); popup.add(installServiceItem); installServiceItem.setEnabled(canUseServices); installServiceItem.addActionListener(e -> SwingUtilities.invokeLater(this::installAsService)); uninstallServiceItem = new MenuItem("Uninstall service" + requiresRootMsg); popup.add(uninstallServiceItem); uninstallServiceItem.setEnabled(canUseServices); uninstallServiceItem.addActionListener(e -> SwingUtilities.invokeLater(this::uninstallService)); if (SystemUtils.IS_OS_WINDOWS) { showServices = new MenuItem("Show services console"); popup.add(showServices); showServices.addActionListener(e -> SwingUtilities.invokeLater(this::showServicesConsole)); } popup.addSeparator(); final MenuItem toolbar = new MenuItem("Show tool window"); popup.add(toolbar); toolbar.addActionListener(actionEvent -> EventQueue.invokeLater(() -> { utilityPanel.toFront(); utilityPanel.setVisible(true); })); MenuItem item; if (Desktop.isDesktopSupported()) { popup.addSeparator(); final Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { dashboardItem = new MenuItem("Open Dashboard"); popup.add(dashboardItem); dashboardItem.addActionListener(actionEvent -> dashboard(desktop)); eXideItem = new MenuItem("Open eXide"); popup.add(eXideItem); eXideItem.addActionListener(actionEvent -> eXide(desktop)); item = new MenuItem("Open Java Admin Client"); popup.add(item); item.addActionListener(actionEvent -> client()); monexItem = new MenuItem("Open Monitoring and Profiling"); popup.add(monexItem); monexItem.addActionListener(actionEvent -> monex(desktop)); } if (desktop.isSupported(Desktop.Action.OPEN)) { popup.addSeparator(); item = new MenuItem("Open exist.log"); popup.add(item); item.addActionListener(new LogActionListener()); } popup.addSeparator(); quitItem = new MenuItem("Quit (and stop server)"); popup.add(quitItem); quitItem.addActionListener(actionEvent -> shutdown(false)); setServiceState(); } return popup; }
From source file:MonitorSaurausRex.MainMenu.java
private static void createAndShowGUI() { //Check the SystemTray support if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;//from www. ja v a2 s . c o m } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("Logo.png", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); trayIcon.setImageAutoSize(true); // Create a popup menu components MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem cb1 = new CheckboxMenuItem("Menu"); CheckboxMenuItem cb2 = new CheckboxMenuItem("Quarantine!"); Menu displayMenu = new Menu("Actions"); MenuItem errorItem = new MenuItem("Cut Connections"); MenuItem warningItem = new MenuItem("Send Reports"); MenuItem infoItem = new MenuItem("Kill Processes"); MenuItem exitItem = new MenuItem("Exit"); //Add components to popup menu popup.add(aboutItem); popup.addSeparator(); popup.add(cb1); popup.add(cb2); popup.addSeparator(); popup.add(displayMenu); displayMenu.add(errorItem); displayMenu.add(warningItem); displayMenu.add(infoItem); popup.add(exitItem); trayIcon.setPopupMenu(popup); try { tray.add(trayIcon); } catch (AWTException e) { System.out.println("TrayIcon could not be added."); return; } trayIcon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "This dialog box is run from System Tray"); } }); aboutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "MonitorSaurausRex, Designed for sec203 group project. The program was designed to be piece of software to combat Ransomware" + " in a corparate enviroment. The Project was created by Luke Barlow, Dayan Patel, Rob Shire and Sian Skiggs."); } }); cb1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int cb1Id = e.getStateChange(); trayIcon.setImageAutoSize(true); if (cb1Id == ItemEvent.SELECTED) { trayIcon.setImageAutoSize(true); } else { trayIcon.setImageAutoSize(true); } } }); cb2.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int cb2Id = e.getStateChange(); if (cb2Id == ItemEvent.SELECTED) { trayIcon.setToolTip("Sun TrayIcon"); } else { trayIcon.setToolTip(null); } } }); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { MenuItem item = (MenuItem) e.getSource(); //TrayIcon.MessageType type = null; System.out.println(item.getLabel()); if ("Error".equals(item.getLabel())) { //type = TrayIcon.MessageType.ERROR; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an error message", TrayIcon.MessageType.ERROR); } else if ("Warning".equals(item.getLabel())) { //type = TrayIcon.MessageType.WARNING; trayIcon.displayMessage("Sun TrayIcon Demo", "This is a warning message", TrayIcon.MessageType.WARNING); } else if ("Info".equals(item.getLabel())) { //type = TrayIcon.MessageType.INFO; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an info message", TrayIcon.MessageType.INFO); } else if ("None".equals(item.getLabel())) { //type = TrayIcon.MessageType.NONE; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an ordinary message", TrayIcon.MessageType.NONE); } } }; errorItem.addActionListener(listener); warningItem.addActionListener(listener); infoItem.addActionListener(listener); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); System.exit(0); } }); }
From source file:com.ln.gui.Main.java
@SuppressWarnings("unchecked") public Main() {/*from w w w . ja v a 2 s .c om*/ System.gc(); setIconImage(Toolkit.getDefaultToolkit().getImage(Configuration.mydir + "\\resources\\icons\\ln6464.png")); DateFormat dd = new SimpleDateFormat("dd"); DateFormat dh = new SimpleDateFormat("HH"); DateFormat dm = new SimpleDateFormat("mm"); Date day = new Date(); Date hour = new Date(); Date minute = new Date(); dayd = Integer.parseInt(dd.format(day)); hourh = Integer.parseInt(dh.format(hour)); minutem = Integer.parseInt(dm.format(minute)); setTitle("Liquid Notify Revision 2"); Description.setBackground(Color.WHITE); Description.setContentType("text/html"); Description.setEditable(false); Getcalendar.Main(); HyperlinkListener hyperlinkListener = new ActivatedHyperlinkListener(f, Description); Description.addHyperlinkListener(hyperlinkListener); //Add components setContentPane(contentPane); setJMenuBar(menuBar); contentPane.setLayout( new MigLayout("", "[220px:230.00:220,grow][209.00px:n:5000,grow]", "[22px][][199.00,grow][grow]")); eventsbtn.setToolTipText("Displays events currently set to notify"); eventsbtn.setMinimumSize(new Dimension(220, 23)); eventsbtn.setMaximumSize(new Dimension(220, 23)); contentPane.add(eventsbtn, "cell 0 0"); NewsArea.setBackground(Color.WHITE); NewsArea.setBorder(new BevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.DARK_GRAY, Color.DARK_GRAY)); NewsArea.setMinimumSize(new Dimension(20, 22)); NewsArea.setMaximumSize(new Dimension(10000, 22)); contentPane.add(NewsArea, "cell 1 0,growx,aligny top"); menuBar.add(File); JMenuItem Settings = new JMenuItem("Settings"); Settings.setIcon(new ImageIcon(Configuration.mydir + "\\resources\\icons\\settings.png")); Settings.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Settings setup = new Settings(); setup.setVisible(true); setup.setLocationRelativeTo(rootPane); } }); File.add(Settings); File.add(mntmNewMenuItem); Tray.setIcon(new ImageIcon(Configuration.mydir + "\\resources\\icons\\ln1616.png")); File.add(Tray); Exit.setIcon(new ImageIcon(Configuration.mydir + "\\resources\\icons\\exit.png")); File.add(Exit); menuBar.add(mnNewMenu); Update.setIcon(new ImageIcon(Configuration.mydir + "\\resources\\icons\\update.png")); Update.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { URL localURL = new URL("http://jiiks.net23.net/tlnotify/online.html"); URLConnection localURLConnection = localURL.openConnection(); BufferedReader localBufferedReader = new BufferedReader( new InputStreamReader(localURLConnection.getInputStream())); String str = localBufferedReader.readLine(); if (!str.contains("YES")) { String st2221 = "Updates server appears to be offline"; JOptionPane pane1 = new JOptionPane(st2221, JOptionPane.WARNING_MESSAGE, JOptionPane.DEFAULT_OPTION); JDialog dialog1 = pane1.createDialog("Update"); dialog1.setLocationRelativeTo(null); dialog1.setVisible(true); dialog1.setAlwaysOnTop(true); } else if (str.contains("YES")) { URL localURL2 = new URL("http://jiiks.net23.net/tlnotify/latestversion.html"); URLConnection localURLConnection1 = localURL2.openConnection(); BufferedReader localBufferedReader2 = new BufferedReader( new InputStreamReader(localURLConnection1.getInputStream())); String str2 = localBufferedReader2.readLine(); Updatechecker.latestver = str2; if (Integer.parseInt(str2) <= Configuration.version) { String st2221 = "No updates available =("; JOptionPane pane1 = new JOptionPane(st2221, JOptionPane.WARNING_MESSAGE, JOptionPane.DEFAULT_OPTION); JDialog dialog1 = pane1.createDialog("Update"); dialog1.setLocationRelativeTo(null); dialog1.setVisible(true); dialog1.setAlwaysOnTop(true); } else if (Integer.parseInt(str2) > Configuration.version) { String st2221 = "Updates available!"; JOptionPane pane1 = new JOptionPane(st2221, JOptionPane.WARNING_MESSAGE, JOptionPane.DEFAULT_OPTION); JDialog dialog1 = pane1.createDialog("Update"); dialog1.setLocationRelativeTo(null); dialog1.setVisible(true); dialog1.setAlwaysOnTop(true); Updatechecker upd = new Updatechecker(); upd.setVisible(true); upd.setLocationRelativeTo(rootPane); upd.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } } } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } }); mnNewMenu.add(Update); JMenuItem About = new JMenuItem("About"); About.setIcon(new ImageIcon(Configuration.mydir + "\\resources\\icons\\about.png")); About.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { About a = new About(); a.setVisible(true); a.setLocationRelativeTo(rootPane); a.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } }); mnNewMenu.add(About); JMenuItem Github = new JMenuItem("Github"); Github.setIcon(new ImageIcon(Configuration.mydir + "\\resources\\icons\\github.png")); Github.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String url = "https://github.com/Jiiks/Liquid-Notify-Rev2"; try { java.awt.Desktop.getDesktop().browse(java.net.URI.create(url)); } catch (IOException e1) { e1.printStackTrace(); } } }); mnNewMenu.add(Github); JMenuItem Thread = new JMenuItem("Thread"); Thread.setIcon(new ImageIcon(Configuration.mydir + "\\resources\\icons\\liquid.png")); Thread.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String url = "http://www.teamliquid.net/forum/viewmessage.php?topic_id=318184"; try { java.awt.Desktop.getDesktop().browse(java.net.URI.create(url)); } catch (IOException e1) { e1.printStackTrace(); } } }); mnNewMenu.add(Thread); Refreshbtn.setToolTipText("Refreshes calendar, please don't spam ^_^"); Refreshbtn.setPreferredSize(new Dimension(90, 20)); Refreshbtn.setMinimumSize(new Dimension(100, 20)); Refreshbtn.setMaximumSize(new Dimension(100, 20)); contentPane.add(Refreshbtn, "flowx,cell 0 1,alignx left"); //Components to secondary panel Titlebox = new JComboBox(); contentPane.add(Titlebox, "cell 1 1,growx,aligny top"); Titlebox.setMinimumSize(new Dimension(20, 20)); Titlebox.setMaximumSize(new Dimension(10000, 20)); //Set other setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 686, 342); contentPane.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); NewsArea.setEnabled(false); NewsArea.setEditable(false); NewsArea.setText("News: " + News); contentPane.add(panel, "cell 0 2,grow"); panel.setLayout(null); final JCalendar calendar = new JCalendar(); calendar.getMonthChooser().setPreferredSize(new Dimension(120, 20)); calendar.getMonthChooser().setMinimumSize(new Dimension(120, 24)); calendar.getYearChooser().setLocation(new Point(20, 0)); calendar.getYearChooser().setMaximum(100); calendar.getYearChooser().setMaximumSize(new Dimension(100, 2147483647)); calendar.getYearChooser().setMinimumSize(new Dimension(50, 20)); calendar.getYearChooser().setPreferredSize(new Dimension(50, 20)); calendar.getYearChooser().getSpinner().setPreferredSize(new Dimension(100, 20)); calendar.getYearChooser().getSpinner().setMinimumSize(new Dimension(100, 20)); calendar.getMonthChooser().getSpinner().setPreferredSize(new Dimension(119, 20)); calendar.getMonthChooser().getSpinner().setMinimumSize(new Dimension(120, 24)); calendar.getDayChooser().getDayPanel().setFont(new Font("Tahoma", Font.PLAIN, 11)); calendar.setDecorationBordersVisible(true); calendar.setTodayButtonVisible(true); calendar.setBackground(Color.LIGHT_GRAY); calendar.setBounds(0, 0, 220, 199); calendar.getDate(); calendar.setWeekOfYearVisible(false); calendar.setDecorationBackgroundVisible(false); calendar.setMaxDayCharacters(2); calendar.getDayChooser().setFont(new Font("Tahoma", Font.PLAIN, 10)); panel.add(calendar); Descriptionscrollpane.setLocation(new Point(100, 100)); Descriptionscrollpane.setMaximumSize(new Dimension(10000, 10000)); Descriptionscrollpane.setMinimumSize(new Dimension(20, 200)); Description.setLocation(new Point(100, 100)); Description.setBorder(new BevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.DARK_GRAY, Color.DARK_GRAY)); Description.setMaximumSize(new Dimension(1000, 400)); Description.setMinimumSize(new Dimension(400, 200)); contentPane.add(Descriptionscrollpane, "cell 1 2 1 2,growx,aligny top"); Descriptionscrollpane.setViewportView(Description); verticalStrut.setMinimumSize(new Dimension(12, 20)); contentPane.add(verticalStrut, "cell 0 1"); Notify.setToolTipText("Adds selected event to notify event list."); Notify.setHorizontalTextPosition(SwingConstants.CENTER); Notify.setPreferredSize(new Dimension(100, 20)); Notify.setMinimumSize(new Dimension(100, 20)); Notify.setMaximumSize(new Dimension(100, 20)); contentPane.add(Notify, "cell 0 1,alignx right"); calendar.getMonthChooser().addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { month = calendar.getMonthChooser().getMonth(); Parser.parse(); } }); calendar.getDayChooser().addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { try { int h = calendar.getMonthChooser().getMonth(); @SuppressWarnings("deprecation") int date = calendar.getDate().getDate(); int month = calendar.getMonthChooser().getMonth() + 1; globmonth = calendar.getMonthChooser().getMonth(); sdate = date; datestring = Integer.toString(sdate); monthstring = Integer.toString(month); String[] Hours = Betaparser.Hours; String[] Titles = Betaparser.STitle; String[] Full = new String[Hours.length]; String[] Minutes = Betaparser.Minutes; String[] Des = Betaparser.Description; String[] Des2 = new String[Betaparser.Description.length]; String Seconds = "00"; String gg; int[] IntHours = new int[Hours.length]; int[] IntMins = new int[Hours.length]; int Events = 0; monthday = monthstring + "|" + datestring + "|"; Titlebox.removeAllItems(); for (int a = 0; a != Hours.length; a++) { IntHours[a] = Integer.parseInt(Hours[a]); IntMins[a] = Integer.parseInt(Minutes[a]); } for (int i1 = 0; i1 != Hours.length; i1++) { if (Betaparser.Events[i1].startsWith(monthday)) { Full[i1] = String.format("%02d:%02d", IntHours[i1], IntMins[i1]) + " | " + Titles[i1]; Titlebox.addItem(Full[i1]); } } } catch (Exception e1) { //Catching mainly due to boot property change } } }); Image image = Toolkit.getDefaultToolkit().getImage(Configuration.mydir + "\\resources\\icons\\ln1616.png"); final SystemTray tray = SystemTray.getSystemTray(); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(true); } }; PopupMenu popup = new PopupMenu(); MenuItem defaultItem = new MenuItem(); defaultItem.addActionListener(listener); TrayIcon trayIcon = null; trayIcon = new TrayIcon(image, "LiquidNotify Revision 2", popup); trayIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { setVisible(true); } });// try { tray.add(trayIcon); } catch (AWTException e) { System.err.println(e); } if (trayIcon != null) { trayIcon.setImage(image); } Tray.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); Titlebox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Descparser.parsedesc(); } }); Refreshbtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Getcalendar.Main(); Descparser.parsedesc(); } }); Notify.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { NOTIFY = Descparser.TTT; NOTIFYD = Descparser.DDD; NOTIFYH = Descparser.HHH; NOTIFYM = Descparser.MMM; int i = events; NOA[i] = NOTIFY; NOD[i] = NOTIFYD; NOH[i] = NOTIFYH; NOM[i] = NOTIFYM; Eventlist[i] = "Starts in: " + Integer.toString(NOD[i]) + " Days " + Integer.toString(NOH[i]) + " Hours " + Integer.toString(NOM[i]) + " Minutes " + " | " + NOA[i]; events = events + 1; Notifylist si = new Notifylist(); si.setVisible(false); si.setBounds(1, 1, 1, 1); si.dispose(); if (thread.getState().name().equals("PENDING")) { thread.execute(); } } }); eventsbtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Notifylist list = new Notifylist(); if (played == 1) { asd.close(); played = 0; } list.setVisible(true); list.setLocationRelativeTo(rootPane); list.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } }); mntmNewMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (thread.getState().name().equals("PENDING")) { thread.execute(); } Userstreams us = new Userstreams(); us.setVisible(true); us.setLocationRelativeTo(rootPane); } }); Exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { //Absolute exit JOptionPane.showMessageDialog(rootPane, "Bye bye :(", "Exit", JOptionPane.INFORMATION_MESSAGE); Runtime ln = Runtime.getRuntime(); ln.gc(); final Frame[] allf = Frame.getFrames(); final Window[] allw = Window.getWindows(); for (final Window allwindows : allw) { allwindows.dispose(); } for (final Frame allframes : allf) { allframes.dispose(); System.exit(0); } } }); }
From source file:streamme.visuals.Main.java
public void loadTray() { if (SystemTray.isSupported()) { tray = SystemTray.getSystemTray(); PopupMenu popup = new PopupMenu(); MenuItem exitItem = new MenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose();//ww w . j av a2 s . c om } }); MenuItem openItem = new MenuItem("Open"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { minimizeToTray(false); } }); popup.add(openItem); popup.add(exitItem); trayIcon = new TrayIcon( Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("res/icon16.png")), "StreamMe", popup); trayIcon.setImageAutoSize(true); trayIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { //minimizeToTray(false); return; } if (evt.getButton() == 1) { minimizeToTray(!isMinimizedToTray()); } } }); addWindowStateListener(new WindowStateListener() { public void windowStateChanged(WindowEvent e) { if (e.getNewState() == ICONIFIED || e.getNewState() == 7) { minimizeToTray(true); } } }); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { minimizeToTray(true); } }); try { tray.add(trayIcon); } catch (AWTException ex) { System.out.println("Error adding icon to tray"); } } }