List of usage examples for javax.swing JFrame addWindowListener
public synchronized void addWindowListener(WindowListener l)
From source file:edu.ku.brc.specify.tools.l10nios.StrLocalizerAppForiOS.java
/** * @param args/*from www.j a v a2 s. com*/ */ public static void main(String[] args) { setAppName("Specify"); //$NON-NLS-1$ System.setProperty(AppPreferences.factoryName, "edu.ku.brc.specify.config.AppPrefsDBIOIImpl"); // Needed by AppReferences //$NON-NLS-1$ for (String s : args) { String[] pairs = s.split("="); //$NON-NLS-1$ if (pairs.length == 2) { if (pairs[0].startsWith("-D")) //$NON-NLS-1$ { //System.err.println("["+pairs[0].substring(2, pairs[0].length())+"]["+pairs[1]+"]"); System.setProperty(pairs[0].substring(2, pairs[0].length()), pairs[1]); } } else { String symbol = pairs[0].substring(2, pairs[0].length()); //System.err.println("["+symbol+"]"); System.setProperty(symbol, symbol); } } // Now check the System Properties String appDir = System.getProperty("appdir"); if (StringUtils.isNotEmpty(appDir)) { UIRegistry.setDefaultWorkingPath(appDir); } String appdatadir = System.getProperty("appdatadir"); if (StringUtils.isNotEmpty(appdatadir)) { UIRegistry.setBaseAppDataDir(appdatadir); } // Then set this IconManager.setApplicationClass(Specify.class); IconManager.loadIcons(XMLHelper.getConfigDir("icons.xml")); //$NON-NLS-1$ //ImageIcon icon = IconManager.getIcon("AppIcon", IconManager.IconSize.Std16); try { ResourceBundle.getBundle("resources", Locale.getDefault()); //$NON-NLS-1$ } catch (MissingResourceException ex) { Locale.setDefault(Locale.ENGLISH); UIRegistry.setResourceLocale(Locale.ENGLISH); } try { if (!System.getProperty("os.name").equals("Mac OS X")) { UIManager.setLookAndFeel(new Plastic3DLookAndFeel()); PlasticLookAndFeel.setPlasticTheme(new DesertBlue()); } } catch (Exception e) { //whatever } AppPreferences localPrefs = AppPreferences.getLocalPrefs(); localPrefs.setDirPath(UIRegistry.getAppDataDir()); boolean doIt = false; if (doIt) { Charset utf8charset = Charset.forName("UTF-8"); Charset iso88591charset = Charset.forName("ISO-8859-1"); ByteBuffer inputBuffer = ByteBuffer.wrap(new byte[] { (byte) 0xC3, (byte) 0xA2 }); // decode UTF-8 CharBuffer data = utf8charset.decode(inputBuffer); // encode ISO-8559-1 ByteBuffer outputBuffer = iso88591charset.encode(data); byte[] outputData = outputBuffer.array(); System.out.println(new String(outputData)); return; } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { UIHelper.OSTYPE osType = UIHelper.getOSType(); if (osType == UIHelper.OSTYPE.Windows) { UIManager.setLookAndFeel(new PlasticLookAndFeel()); PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue()); } else if (osType == UIHelper.OSTYPE.Linux) { UIManager.setLookAndFeel(new PlasticLookAndFeel()); } } catch (Exception e) { log.error("Can't change L&F: ", e); //$NON-NLS-1$ } JFrame frame = new JFrame(getResourceString("StrLocalizerApp.AppTitle")); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); final StrLocalizerAppForiOS sl = new StrLocalizerAppForiOS(); sl.addMenuBar(frame); frame.setContentPane(sl); frame.setSize(768, 1024); //Dimension size = frame.getPreferredSize(); //size.height = 500; //frame.setSize(size); frame.addWindowListener(sl); IconManager.setApplicationClass(Specify.class); frame.setIconImage(IconManager.getImage(IconManager.makeIconName("SpecifyWhite32")).getImage()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { sl.startUp(); } }); } }); }
From source file:Demo3D.java
/** * Main of the Demo program. Take the graphic environment of the * workstation.//w ww . j a va 2 s . c o m */ public static void main(String args[]) { JFrame jFrameDemo = new Demo3D(); // To be sure to stop the application when the frame is closed. WindowListener winListener = new WindowAdapter() { public void windowClosing(WindowEvent event) { System.exit(0); } }; jFrameDemo.addWindowListener(winListener); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); screenwidth = (int) screenSize.getWidth(); screenheight = (int) screenSize.getHeight(); jFrameDemo.setSize(screenwidth, screenheight); // Turn on the visibility of the frame. jFrameDemo.setVisible(true); fpsThread.start(); }
From source file:org.jets3t.apps.cockpit.Cockpit.java
/** * Runs Cockpit as a stand-alone application. * @param args// w w w . ja va 2s . c o m * @throws Exception */ public static void main(String args[]) throws Exception { // When running on OS X, display app menu in the right place (i.e. not the app window) System.setProperty("apple.laf.useScreenMenuBar", "true"); JFrame ownerFrame = new JFrame("JetS3t Cockpit"); ownerFrame.addWindowListener(new WindowListener() { public void windowOpened(WindowEvent e) { } public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } public void windowClosed(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } }); new Cockpit(ownerFrame); }
From source file:Tcpbw100.java
public static void main(String[] args) { JFrame frame = new JFrame("ANL/Internet2 NDT (applet)"); if (args.length != 5) { System.out.println("Usage: java -jar Tcpbw100.jar " + "HOST ReportHost ReportPort UserID MeasurementID ConnectionId"); System.exit(0);//w w w. j ava 2s .c o m } final Tcpbw100 applet = new Tcpbw100(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { applet.destroy(); System.exit(0); } }); applet.app_id = "java"; applet.isApplication = true; applet.host = args[0]; applet.reportHost = args[1]; applet.reportPort = new Integer(args[2]); applet.userId = args[3]; applet.connectionId = args[4]; frame.getContentPane().add(applet); frame.setSize(700, 320); applet.init(); applet.start(); frame.setVisible(true); }
From source file:Main.java
/** * create JFrame that has a WindowListener object that was invoked * System.exit(0) by pushing close button. *///from w w w . ja va2s. c om public static JFrame getTestFrame(String title) { JFrame f = new JFrame(title); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); return f; }
From source file:Main.java
public static void activateWindowClosingButton(JFrame frame) { frame.addWindowListener(new WindowAdapter() { @Override// www .j a v a2 s . c o m public void windowClosing(WindowEvent evnt) { evnt.getWindow().setVisible(false); evnt.getWindow().dispose(); } }); }
From source file:Main.java
public static void activateWindowClosingAndSystemExitButton(JFrame frame) { frame.addWindowListener(new WindowAdapter() { @Override//w ww.j a va 2 s .co m public void windowClosing(WindowEvent evnt) { evnt.getWindow().setVisible(false); evnt.getWindow().dispose(); System.exit(0); } }); }
From source file:Main.java
/** * Causes the given frame to simply go invisible when closed. Calls * {@link JFrame#setDefaultCloseOperation(int)} with <tt>DO_NOTHING_ON_CLOSE</tt>, * then adds a {@link WindowListener} that calls {@link JFrame#setVisible(boolean)} * with false in {@link WindowListener#windowClosing(WindowEvent)} * @param frame the JFrame to make go invisible on close *//*w w w . ja va 2s.co m*/ public static void goInvisibleOnClose(final JFrame frame) { frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { frame.setVisible(false); } }); }
From source file:ch.descabato.browser.BackupBrowser.java
public static void main2(final String[] args) throws InterruptedException, InvocationTargetException, SecurityException, IOException { if (args.length > 1) throw new IllegalArgumentException( "SYNTAX: java... " + BackupBrowser.class.getName() + " [initialPath]"); SwingUtilities.invokeAndWait(new Runnable() { @Override//w w w. j a v a 2 s .c o m public void run() { tryLoadSubstanceLookAndFeel(); final JFrame f = new JFrame("OtrosVfsBrowser demo"); f.addWindowListener(finishedListener); Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout()); DataConfiguration dc = null; final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); File favoritesFile = new File("favorites.properties"); propertiesConfiguration.setFile(favoritesFile); if (favoritesFile.exists()) { try { propertiesConfiguration.load(); } catch (ConfigurationException e) { e.printStackTrace(); } } dc = new DataConfiguration(propertiesConfiguration); propertiesConfiguration.setAutoSave(true); final VfsBrowser comp = new VfsBrowser(dc, (args.length > 0) ? args[0] : null); comp.setSelectionMode(SelectionMode.FILES_ONLY); comp.setMultiSelectionEnabled(true); comp.setApproveAction(new AbstractAction(Messages.getMessage("demo.showContentButton")) { @Override public void actionPerformed(ActionEvent e) { FileObject[] selectedFiles = comp.getSelectedFiles(); System.out.println("Selected files count=" + selectedFiles.length); for (FileObject selectedFile : selectedFiles) { try { FileSize fileSize = new FileSize(selectedFile.getContent().getSize()); System.out.println(selectedFile.getName().getURI() + ": " + fileSize.toString()); Desktop.getDesktop() .open(new File(new URI(selectedFile.getURL().toExternalForm()))); // byte[] bytes = readBytes(selectedFile.getContent().getInputStream(), 150 * 1024l); // JScrollPane sp = new JScrollPane(new JTextArea(new String(bytes))); // JDialog d = new JDialog(f); // d.setTitle("Content of file: " + selectedFile.getName().getFriendlyURI()); // d.getContentPane().add(sp); // d.setSize(600, 400); // d.setVisible(true); } catch (Exception e1) { LOGGER.error("Failed to read file", e1); JOptionPane.showMessageDialog(f, (e1.getMessage() == null) ? e1.toString() : e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } }); comp.setCancelAction(new AbstractAction(Messages.getMessage("general.cancelButtonText")) { @Override public void actionPerformed(ActionEvent e) { f.dispose(); try { propertiesConfiguration.save(); } catch (ConfigurationException e1) { e1.printStackTrace(); } System.exit(0); } }); contentPane.add(comp); f.pack(); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); while (!finished) Thread.sleep(100); }
From source file:components.PasswordDemo.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event dispatch thread./* w ww . j a v a2 s .com*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("PasswordDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. final PasswordDemo newContentPane = new PasswordDemo(frame); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane); //Make sure the focus goes to the right component //whenever the frame is initially given the focus. frame.addWindowListener(new WindowAdapter() { public void windowActivated(WindowEvent e) { newContentPane.resetFocus(); } }); //Display the window. frame.pack(); frame.setVisible(true); }