List of usage examples for java.awt SystemTray getSystemTray
public static SystemTray getSystemTray()
From source file:de.jakop.ngcalsync.application.TrayStarter.java
private StatefulTrayIcon getTrayIcon() { if (icon == null) { try {//from w w w . ja v a 2 s . com icon = new StatefulTrayIcon(); SystemTray.getSystemTray().add(icon); } catch (final AWTException e) { log.error(TechMessage.get().MSG_TRAY_ICON_NOT_LOADABLE(), e); } catch (final IOException e) { log.error(TechMessage.get().MSG_TRAY_ICON_NOT_LOADABLE(), e); } } return icon; }
From source file:neembuu.uploader.NeembuuUploader.java
private void setUpTrayIcon() { if (SystemTray.isSupported()) { //trayIcon.setImageAutoSize(true); It renders the icon very poorly. //So we render the icon ourselves with smooth settings. {//ww w. j ava2s . c o m Dimension d = SystemTray.getSystemTray().getTrayIconSize(); trayIcon = new TrayIcon(getIconImage().getScaledInstance(d.width, d.height, Image.SCALE_SMOOTH)); } //trayIcon = new TrayIcon(getIconImage()); //trayIcon.setImageAutoSize(true); trayIcon.setToolTip(Translation.T().trayIconToolTip()); trayIcon.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NULogger.getLogger().info("System tray double clicked"); setExtendedState(JFrame.NORMAL); setVisible(true); repaint(); SystemTray.getSystemTray().remove(trayIcon); } }); } }
From source file:jatoo.app.App.java
public App(final String title) { this.title = title; ///*w ww. j a v a 2 s . co m*/ // load properties properties = new AppProperties(new File(getWorkingDirectory(), "app.properties")); properties.loadSilently(); // // resources texts = new ResourcesTexts(getClass(), new ResourcesTexts(App.class)); images = new ResourcesImages(getClass(), new ResourcesImages(App.class)); // // create & initialize the window if (isDialog()) { window = new JDialog((Frame) null, getTitle()); if (isUndecorated()) { ((JDialog) window).setUndecorated(true); ((JDialog) window).setBackground(new Color(0, 0, 0, 0)); } ((JDialog) window).setResizable(isResizable()); } else { window = new JFrame(getTitle()); if (isUndecorated()) { ((JFrame) window).setUndecorated(true); ((JFrame) window).setBackground(new Color(0, 0, 0, 0)); } ((JFrame) window).setResizable(isResizable()); } window.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { System.exit(0); } @Override public void windowIconified(final WindowEvent e) { if (isHideWhenMinimized()) { hide(); } } }); // // set icon images // is either all icons from initializer package // or all icons from app package List<Image> windowIconImages = new ArrayList<>(); String[] windowIconImagesNames = new String[] { "016", "020", "022", "024", "032", "048", "064", "128", "256", "512" }; for (String size : windowIconImagesNames) { try { windowIconImages.add(new ImageIcon(getClass().getResource("app-icon-" + size + ".png")).getImage()); } catch (Exception e) { } } if (windowIconImages.size() == 0) { for (String size : windowIconImagesNames) { try { windowIconImages .add(new ImageIcon(App.class.getResource("app-icon-" + size + ".png")).getImage()); } catch (Exception e) { } } } window.setIconImages(windowIconImages); // // this is the place for to call init method // after all local components are created // from now (after init) is only configuration init(); // // set content pane ( and ansure transparency ) JComponent contentPane = getContentPane(); contentPane.setOpaque(false); ((RootPaneContainer) window).setContentPane(contentPane); // // pack the window right after the set of the content pane window.pack(); // // center window (as default in case restore fails) // and try to restore the last location window.setLocationRelativeTo(null); window.setLocation(properties.getLocation(window.getLocation())); if (!isUndecorated()) { if (properties.getLastUndecorated(isUndecorated()) == isUndecorated()) { if (isResizable() && isSizePersistent()) { final String currentLookAndFeel = String.valueOf(UIManager.getLookAndFeel()); if (properties.getLastLookAndFeel(currentLookAndFeel).equals(currentLookAndFeel)) { window.setSize(properties.getSize(window.getSize())); } } } } // // fix location if out of screen Rectangle intersection = window.getGraphicsConfiguration().getBounds().intersection(window.getBounds()); if ((intersection.width < window.getWidth() * 1 / 2) || (intersection.height < window.getHeight() * 1 / 2)) { UIUtils.setWindowLocationRelativeToScreen(window); } // // restore some properties setAlwaysOnTop(properties.isAlwaysOnTop()); setHideWhenMinimized(properties.isHideWhenMinimized()); setTransparency(properties.getTransparency(transparency)); // // null is also a good value for margins glue gaps (is [0,0,0,0]) Insets marginsGlueGaps = getMarginsGlueGaps(); if (marginsGlueGaps == null) { marginsGlueGaps = new Insets(0, 0, 0, 0); } // // glue to margins on Ctrl + ARROWS if (isGlueToMarginsOnCtrlArrows()) { UIUtils.setActionForCtrlDownKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginBottom(window, marginsGlueGaps.bottom)); UIUtils.setActionForCtrlLeftKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginLeft(window, marginsGlueGaps.left)); UIUtils.setActionForCtrlRightKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginRight(window, marginsGlueGaps.right)); UIUtils.setActionForCtrlUpKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginTop(window, marginsGlueGaps.top)); } // // drag to move ( when provided component is not null ) JComponent dragToMoveComponent = getDragToMoveComponent(); if (dragToMoveComponent != null) { // // move the window by dragging the UI component int marginsGlueRange = Math.min(window.getGraphicsConfiguration().getBounds().width, window.getGraphicsConfiguration().getBounds().height); marginsGlueRange /= 60; marginsGlueRange = Math.max(marginsGlueRange, 15); UIUtils.forwardDragAsMove(dragToMoveComponent, window, marginsGlueRange, marginsGlueGaps); // // window popup dragToMoveComponent.addMouseListener(new MouseAdapter() { public void mouseReleased(final MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { windowPopup = getWindowPopup(e.getLocationOnScreen()); windowPopup.setVisible(true); } } }); // // always dispose the popup when window lose the focus window.addFocusListener(new FocusAdapter() { public void focusLost(final FocusEvent e) { if (windowPopup != null) { windowPopup.setVisible(false); windowPopup = null; } } }); } // // tray icon if (hasTrayIcon()) { if (SystemTray.isSupported()) { Image trayIconImage = windowIconImages.get(0); Dimension trayIconSize = SystemTray.getSystemTray().getTrayIconSize(); for (Image windowIconImage : windowIconImages) { if (Math.abs(trayIconSize.width - windowIconImage.getWidth(null)) < Math .abs(trayIconImage.getWidth(null) - windowIconImage.getWidth(null))) { trayIconImage = windowIconImage; } } final TrayIcon trayIcon = new TrayIcon(trayIconImage); trayIcon.setPopupMenu(getTrayIconPopup()); trayIcon.addMouseListener(new MouseAdapter() { public void mouseClicked(final MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() >= 2) { if (window.isVisible()) { hide(); } else { show(); } } } } }); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException e) { logger.error( "unexpected exception trying to add the tray icon ( the desktop system tray is missing? )", e); } } else { logger.error("the system tray is not supported on the current platform"); } } // // hidden or not if (properties.isVisible()) { window.setVisible(true); } // // close the splash screen // if there is one try { SplashScreen splash = SplashScreen.getSplashScreen(); if (splash != null) { splash.close(); } } catch (UnsupportedOperationException e) { getLogger().info("splash screen not supported", e); } // // add shutdown hook for #destroy() Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { App.this.destroy(); } }); // // after init afterInit(); }
From source file:com.jsystem.j2autoit.AutoItAgent.java
private static void createAndShowGUI() { //Check the SystemTray support if (!SystemTray.isSupported()) { Log.error("SystemTray is not supported\n"); return;//from w ww . jav a 2 s. c o m } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("images/jsystem_ico.gif", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components final MenuItem aboutItem = new MenuItem("About"); final MenuItem startAgentItem = new MenuItem("Start J2AutoIt Agent"); final MenuItem stopAgentItem = new MenuItem("Stop J2AutoIt Agent"); final MenuItem exitItem = new MenuItem("Exit"); final MenuItem changePortItem = new MenuItem("Setting J2AutoIt Port"); final MenuItem deleteTemporaryFilesItem = new MenuItem("Delete J2AutoIt Script"); final MenuItem temporaryHistoryFilesItem = new MenuItem("History Size"); final MenuItem displayLogFile = new MenuItem("Log"); final MenuItem forceShutDownTimeOutItem = new MenuItem("Force ShutDown TimeOut"); final MenuItem writeConfigurationToFile = new MenuItem("Save Configuration To File"); final CheckboxMenuItem debugModeItem = new CheckboxMenuItem("Debug Mode", isDebug); final CheckboxMenuItem forceAutoItShutDownItem = new CheckboxMenuItem("Force AutoIt Script ShutDown", isForceAutoItShutDown); final CheckboxMenuItem autoDeleteHistoryItem = new CheckboxMenuItem("Auto Delete History", isAutoDeleteFiles); final CheckboxMenuItem useAutoScreenShot = new CheckboxMenuItem("Auto Screenshot", isUseScreenShot); //Add components to popup menu popup.add(aboutItem); popup.add(writeConfigurationToFile); popup.addSeparator(); popup.add(forceAutoItShutDownItem); popup.add(forceShutDownTimeOutItem); popup.addSeparator(); popup.add(debugModeItem); popup.add(displayLogFile); popup.add(useAutoScreenShot); popup.addSeparator(); popup.add(autoDeleteHistoryItem); popup.add(deleteTemporaryFilesItem); popup.add(temporaryHistoryFilesItem); popup.addSeparator(); popup.add(changePortItem); popup.addSeparator(); popup.add(startAgentItem); popup.add(stopAgentItem); popup.addSeparator(); popup.add(exitItem); trayIcon.setToolTip("J2AutoIt Agent"); trayIcon.setImageAutoSize(true); trayIcon.setPopupMenu(popup); final DisplayLogFile displayLog = new DisplayLogFile(); try { tray.add(trayIcon); } catch (AWTException e) { Log.error("TrayIcon could not be added.\n"); return; } trayIcon.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { startAgentItem.setEnabled(!serverState); stopAgentItem.setEnabled(serverState); deleteTemporaryFilesItem.setEnabled(isDebug && HistoryFile.containEntries()); autoDeleteHistoryItem.setEnabled(isDebug); temporaryHistoryFilesItem.setEnabled(isDebug && isAutoDeleteFiles); displayLogFile.setEnabled(isDebug); forceShutDownTimeOutItem.setEnabled(isForceAutoItShutDown); } @Override public void mouseReleased(MouseEvent e) { } }); writeConfigurationToFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { AutoItProperties.DEBUG_MODE_KEY.setValue(isDebug.toString()); AutoItProperties.AUTO_DELETE_TEMPORARY_SCRIPT_FILE_KEY.setValue(isAutoDeleteFiles.toString()); AutoItProperties.AUTO_IT_SCRIPT_HISTORY_SIZE_KEY.setValue(DEFAULT_HistorySize.toString()); AutoItProperties.FORCE_AUTO_IT_PROCESS_SHUTDOWN_KEY.setValue(isForceAutoItShutDown.toString()); AutoItProperties.AGENT_PORT_KEY.setValue(webServicePort.toString()); AutoItProperties.SERVER_UP_ON_INIT_KEY.setValue(serverState.toString()); if (!AutoItProperties.savePropertiesFileSafely()) { Log.error("Fail to save properties file"); } } }); debugModeItem.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { isDebug = (e.getStateChange() == ItemEvent.SELECTED); deleteTemporaryFilesItem.setEnabled(isDebug && HistoryFile.containEntries()); Log.infoLog("Keeping the temp file is " + (isDebug ? "en" : "dis") + "able\n"); trayIcon.displayMessage((isDebug ? "Debug" : "Normal") + " Mode", "The system will " + (isDebug ? "not " : "") + "delete \nthe temporary autoIt scripts." + (isDebug ? "\nSee log file for more info." : ""), MessageType.INFO); } }); useAutoScreenShot.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { isUseScreenShot = (e.getStateChange() == ItemEvent.SELECTED); Log.infoLog("Auto screenshot is " + (isUseScreenShot ? "" : "in") + "active\n"); } }); forceAutoItShutDownItem.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { isForceAutoItShutDown = (e.getStateChange() == ItemEvent.SELECTED); Log.infoLog((isForceAutoItShutDown ? "Force" : "Soft") + " AutoIt Script ShutDown\n"); trayIcon.displayMessage("AutoIt Script Termination", (isForceAutoItShutDown ? "Hard shutdown" : "Soft shutdown"), MessageType.INFO); } }); autoDeleteHistoryItem.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { isAutoDeleteFiles = (e.getStateChange() == ItemEvent.SELECTED); Log.infoLog((isAutoDeleteFiles ? "Auto" : "Manual") + " AutoIt Script Deletion\n"); trayIcon.displayMessage("AutoIt Script Deletion", (isAutoDeleteFiles ? "Auto" : "Manual") + " Mode", MessageType.INFO); if (isAutoDeleteFiles) { HistoryFile.init(); } else { HistoryFile.close(); } } }); forceShutDownTimeOutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { String timeOutAsString = JOptionPane.showInputDialog( "Please Insert Force ShutDown TimeOut (in seconds)", String.valueOf(shutDownTimeOut / 1000)); try { shutDownTimeOut = 1000 * Long.parseLong(timeOutAsString); } catch (Exception e2) { } Log.infoLog("Setting the force shutdown time out to : " + (shutDownTimeOut / 1000) + " seconds.\n"); } }); displayLogFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { try { displayLog.reBuild(Log.getCurrentLogs()); displayLog.actionPerformed(actionEvent); } catch (Exception e2) { } } }); temporaryHistoryFilesItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { String historySize = JOptionPane.showInputDialog("Please Insert History AutoIt Script Files", String.valueOf(HistoryFile.getHistory_Size())); try { int temp = Integer.parseInt(historySize); if (temp > 0) { if (HistoryFile.getHistory_Size() != temp) { HistoryFile.setHistory_Size(temp); Log.infoLog("The history files size is " + historySize + NEW_LINE); } } else { Log.warning("Illegal History Size: " + historySize + NEW_LINE); } } catch (Exception exception) { Log.throwableLog(exception.getMessage(), exception); } } }); deleteTemporaryFilesItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { HistoryFile.forceDeleteAll(); } }); startAgentItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { runWebServer(); } }); stopAgentItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { shutDownWebServer(); } }); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { JOptionPane.showMessageDialog(null, "J2AutoIt Agent By JSystem And Aqua Software"); } }); changePortItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { String portAsString = JOptionPane.showInputDialog("Please Insert new Port", String.valueOf(webServicePort)); if (portAsString != null) { try { int temp = Integer.parseInt(portAsString); if (temp > 1000) { if (temp != webServicePort) { webServicePort = temp; shutDownWebServer(); startAutoItWebServer(webServicePort); runWebServer(); } } else { Log.warning("Port number should be greater then 1000\n"); } } catch (Exception exception) { Log.error("Illegal port number\n"); return; } } } }); exitItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { tray.remove(trayIcon); shutDownWebServer(); Log.info("Exiting from J2AutoIt Agent\n"); System.exit(0); } }); }
From source file:org.shelloid.vpt.agent.App.java
private void setupSystemTray() { if (SystemTray.isSupported()) { try {/* w w w . j av a 2s . 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:net.sourceforge.entrainer.gui.EntrainerFX.java
private void addSystemTrayIcon() { if (!SystemTray.isSupported()) return;//from w ww .j a va2 s. c om TrayIcon icon = new TrayIcon(this.icon.getImage()); icon.setPopupMenu(getTrayIconPopup()); icon.setToolTip("EntrainerFX"); try { SystemTray.getSystemTray().add(icon); } catch (AWTException e) { GuiUtil.handleProblem(e); } }
From source file:org.kontalk.view.View.java
private void removeTray() { if (mTrayIcon != null) { SystemTray tray = SystemTray.getSystemTray(); tray.remove(mTrayIcon); mTrayIcon = null; } }
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 ava2 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:org.gtdfree.GTDFree.java
/** * @param args//from w w w.ja v a2 s .c o m */ @SuppressWarnings("static-access") public static void main(final String[] args) { //ApplicationHelper.changeDefaultFontSize(6, "TextField"); //ApplicationHelper.changeDefaultFontSize(6, "TextArea"); //ApplicationHelper.changeDefaultFontSize(6, "Table"); //ApplicationHelper.changeDefaultFontSize(6, "Tree"); //ApplicationHelper.changeDefaultFontStyle(Font.BOLD, "Tree"); final Logger logger = Logger.getLogger(GTDFree.class); logger.setLevel(Level.ALL); BasicConfigurator.configure(); Options op = new Options(); op.addOption("data", true, Messages.getString("GTDFree.Options.data")); //$NON-NLS-1$ //$NON-NLS-2$ op.addOption("eodb", true, Messages.getString("GTDFree.Options.eodb")); //$NON-NLS-1$ //$NON-NLS-2$ op.addOption("exml", true, Messages.getString("GTDFree.Options.exml")); //$NON-NLS-1$ //$NON-NLS-2$ op.addOption("h", "help", false, Messages.getString("GTDFree.Options.help")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ op.addOption("log", true, Messages.getString("GTDFree.Options.log")); //$NON-NLS-1$ //$NON-NLS-2$ Options op2 = new Options(); op2.addOption(OptionBuilder.hasArg().isRequired(false) .withDescription(new MessageFormat(Messages.getString("GTDFree.Options.lang")) //$NON-NLS-1$ .format(new Object[] { "'en'", "'de', 'en'" })) //$NON-NLS-1$ //$NON-NLS-2$ .withArgName("de|en") //$NON-NLS-1$ .withLongOpt("Duser.language") //$NON-NLS-1$ .withValueSeparator('=').create()); op2.addOption(OptionBuilder.hasArg().isRequired(false) .withDescription(new MessageFormat(Messages.getString("GTDFree.Options.laf")).format(new Object[] { //$NON-NLS-1$ "'com.jgoodies.looks.plastic.Plastic3DLookAndFeel', 'com.jgoodies.looks.plastic.PlasticLookAndFeel', 'com.jgoodies.looks.plastic.PlasticXPLookAndFeel', 'com.jgoodies.looks.windows.WindowsLookAndFeel' (only on MS Windows), 'com.sun.java.swing.plaf.gtk.GTKLookAndFeel' (only on Linux with GTK), 'com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel', 'javax.swing.plaf.metal.MetalLookAndFeel'" })) //$NON-NLS-1$ .withLongOpt("Dswing.crossplatformlaf") //$NON-NLS-1$ .withValueSeparator('=').create()); CommandLineParser clp = new GnuParser(); CommandLine cl = null; try { cl = clp.parse(op, args); } catch (ParseException e1) { logger.error("Parse error.", e1); //$NON-NLS-1$ } System.out.print("GTD-Free"); //$NON-NLS-1$ String ver = ""; //$NON-NLS-1$ try { System.out.println(" version " + (ver = ApplicationHelper.getVersion())); //$NON-NLS-1$ } catch (Exception e) { System.out.println(); // ignore } if (true) { // || cl.hasOption("help") || cl.hasOption("h")) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("java [Java options] -jar gtd-free.jar [gtd-free options]" //$NON-NLS-1$ , "[gtd-free options] - " + Messages.getString("GTDFree.Options.appop") //$NON-NLS-1$ //$NON-NLS-2$ , op, "[Java options] - " + new MessageFormat(Messages.getString("GTDFree.Options.javaop")) //$NON-NLS-1$//$NON-NLS-2$ .format(new Object[] { "'-jar'" }) //$NON-NLS-1$ , false); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); hf.setLongOptPrefix("-"); //$NON-NLS-1$ hf.setWidth(88); hf.printOptions(pw, hf.getWidth(), op2, hf.getLeftPadding(), hf.getDescPadding()); String s = sw.getBuffer().toString(); s = s.replaceAll("\\A {3}", ""); //$NON-NLS-1$ //$NON-NLS-2$ s = s.replaceAll("\n {3}", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ s = s.replaceAll(" <", "=<"); //$NON-NLS-1$ //$NON-NLS-2$ System.out.print(s); } String val = cl.getOptionValue("data"); //$NON-NLS-1$ if (val != null) { System.setProperty(ApplicationHelper.DATA_PROPERTY, val); System.setProperty(ApplicationHelper.TITLE_PROPERTY, "1"); //$NON-NLS-1$ } else { System.setProperty(ApplicationHelper.TITLE_PROPERTY, "0"); //$NON-NLS-1$ } val = cl.getOptionValue("log"); //$NON-NLS-1$ if (val != null) { Level l = Level.toLevel(val, Level.ALL); logger.setLevel(l); } if (!ApplicationHelper.tryLock(null)) { System.out.println("Instance of GTD-Free already running, pushing it to be visible..."); //$NON-NLS-1$ remotePushVisible(); System.out.println("Instance of GTD-Free already running, exiting."); //$NON-NLS-1$ System.exit(0); } if (!"OFF".equalsIgnoreCase(val)) { //$NON-NLS-1$ RollingFileAppender f = null; try { f = new RollingFileAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN), ApplicationHelper.getLogFileName(), true); f.setMaxBackupIndex(3); BasicConfigurator.configure(f); f.rollOver(); } catch (IOException e2) { logger.error("Logging error.", e2); //$NON-NLS-1$ } } logger.info("GTD-Free " + ver + " started."); //$NON-NLS-1$ //$NON-NLS-2$ logger.debug("Args: " + Arrays.toString(args)); //$NON-NLS-1$ logger.info("Using data in: " + ApplicationHelper.getDataFolder()); //$NON-NLS-1$ if (cl.getOptionValue("exml") != null || cl.getOptionValue("eodb") != null) { //$NON-NLS-1$ //$NON-NLS-2$ GTDFreeEngine engine = null; try { engine = new GTDFreeEngine(); } catch (Exception e1) { logger.fatal("Fatal error, exiting.", e1); //$NON-NLS-1$ } val = cl.getOptionValue("exml"); //$NON-NLS-1$ if (val != null) { File f1 = new File(val); if (f1.isDirectory()) { f1 = new File(f1, "gtd-free-" + ApplicationHelper.formatLongISO(new Date()) + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ } try { f1.getParentFile().mkdirs(); } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } try { engine.getGTDModel().exportXML(f1); logger.info("Data successfully exported as XML to " + f1.toString()); //$NON-NLS-1$ } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } } val = cl.getOptionValue("eodb"); //$NON-NLS-1$ if (val != null) { File f1 = new File(val); if (f1.isDirectory()) { f1 = new File(f1, "gtd-free-" + ApplicationHelper.formatLongISO(new Date()) + ".odb-xml"); //$NON-NLS-1$ //$NON-NLS-2$ } try { f1.getParentFile().mkdirs(); } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } try { GTDData data = engine.getGTDModel().getDataRepository(); if (data instanceof GTDDataODB) { try { ((GTDDataODB) data).exportODB(f1); } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } logger.info("Data successfully exported as ODB to " + f1.toString()); //$NON-NLS-1$ } else { logger.info("Data is not stored in ODB database, nothing is exported."); //$NON-NLS-1$ } } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } } try { engine.close(true, false); } catch (Exception e) { logger.error("Internal error.", e); //$NON-NLS-1$ } return; } logger.debug("Using OS '" + System.getProperty("os.name") + "', '" + System.getProperty("os.version") //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ + "', '" + System.getProperty("os.arch") + "'."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ logger.debug("Using Java '" + System.getProperty("java.runtime.name") + "' version '" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + System.getProperty("java.runtime.version") + "'."); //$NON-NLS-1$ //$NON-NLS-2$ Locale[] supported = { Locale.ENGLISH, Locale.GERMAN }; String def = Locale.getDefault().getLanguage(); boolean toSet = true; for (Locale locale : supported) { toSet &= !locale.getLanguage().equals(def); } if (toSet) { logger.debug("System locale '" + def + "' not supported, setting to '" + Locale.ENGLISH.getLanguage() //$NON-NLS-1$//$NON-NLS-2$ + "'."); //$NON-NLS-1$ try { Locale.setDefault(Locale.ENGLISH); } catch (Exception e) { logger.warn("Setting default locale failed.", e); //$NON-NLS-1$ } } else { logger.debug("Using locale '" + Locale.getDefault().toString() + "'."); //$NON-NLS-1$ //$NON-NLS-2$ } try { //System.setProperty("swing.crossplatformlaf", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "com.jgoodies.looks.plastic.Plastic3DLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "com.jgoodies.looks.plastic.PlasticLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "javax.swing.plaf.metal.MetalLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); if (System.getProperty("swing.crossplatformlaf") == null) { //$NON-NLS-1$ String osName = System.getProperty("os.name"); //$NON-NLS-1$ if (osName != null && osName.toLowerCase().indexOf("windows") != -1) { //$NON-NLS-1$ UIManager.setLookAndFeel("com.jgoodies.looks.windows.WindowsLookAndFeel"); //$NON-NLS-1$ } else { try { // we prefer to use native L&F, many systems support GTK, even if Java thinks it is not supported UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); //$NON-NLS-1$ } catch (Throwable e) { logger.debug("GTK L&F not supported.", e); //$NON-NLS-1$ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } } } } catch (Throwable e) { logger.warn("Setting L&F failed.", e); //$NON-NLS-1$ } logger.debug("Using L&F '" + UIManager.getLookAndFeel().getName() + "' by " //$NON-NLS-1$//$NON-NLS-2$ + UIManager.getLookAndFeel().getClass().getName()); try { final GTDFree application = new GTDFree(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { application.getJFrame(); application.restore(); //application.getJFrame().setVisible(true); application.pushVisible(); ApplicationHelper.executeInBackground(new Runnable() { @Override public void run() { if (SystemTray.isSupported() && application.getEngine().getGlobalProperties() .getBoolean(GlobalProperties.SHOW_TRAY_ICON, false)) { try { SystemTray.getSystemTray().add(application.getTrayIcon()); } catch (AWTException e) { logger.error("Failed to activate system tray icon.", e); //$NON-NLS-1$ } } } }); ApplicationHelper.executeInBackground(new Runnable() { @Override public void run() { application.exportRemote(); } }); if (application.getEngine().getGlobalProperties() .getBoolean(GlobalProperties.CHECK_FOR_UPDATE_AT_START, true)) { ApplicationHelper.executeInBackground(new Runnable() { @Override public void run() { application.checkForUpdates(false); } }); } } catch (Throwable t) { t.printStackTrace(); logger.fatal("Failed to start application, exiting.", t); //$NON-NLS-1$ if (application != null) { application.close(true); } System.exit(0); } } }); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { application.close(true); } catch (Exception e) { logger.warn("Failed to stop application.", e); //$NON-NLS-1$ } logger.info("Closed."); //$NON-NLS-1$ ApplicationHelper.releaseLock(); LogManager.shutdown(); } }); } catch (Throwable t) { logger.fatal("Initialization failed, exiting.", t); //$NON-NLS-1$ t.printStackTrace(); System.exit(0); } }
From source file:com.ln.gui.Main.java
@SuppressWarnings("unchecked") public Main() {/*ww w .j a va2s. c o m*/ 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); } } }); }