List of usage examples for javax.swing WindowConstants EXIT_ON_CLOSE
int EXIT_ON_CLOSE
To view the source code for javax.swing WindowConstants EXIT_ON_CLOSE.
Click Source Link
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(new Main().makeUI()); f.setSize(320, 240);// w ww . j a v a 2s. com f.setVisible(true); }
From source file:CubaHSQLDBServer.java
public static void main(final String[] args) { final boolean validInit = args.length > 2; SwingUtilities.invokeLater(new Runnable() { @Override// w w w . jav a 2s . com public void run() { final CubaHSQLDBServer monitor = new CubaHSQLDBServer(); monitor.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); monitor.setLocationRelativeTo(null); monitor.setVisible(true); if (validInit) { Integer dbPort = Integer.valueOf(args[0]); String dbPath = args[1]; String dbName = args[2]; final HSQLServer server = monitor.startServer(dbPort, dbPath, dbName); if (server != null) { monitor.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { try { server.shutdownCatalogs(2 /* NORMAL CLOSE MODE */); } catch (RuntimeException exception) { // Ignore exceptions from server. } } }); } } else { String argStr = StringUtils.join(args, ' '); monitor.setStatus(String.format( "Invalid usage (args: '%s')\nExpected arguments: <port> <dbPath> <dbName>", argStr)); } } }); }
From source file:Main.java
public static void main(String[] args) { JProgressBar progressBar = new JProgressBar(); progressBar.setOpaque(false);//from w w w. ja v a 2 s .c om progressBar.setUI(new GradientPalletProgressBarUI()); JPanel p = new JPanel(); p.add(progressBar); p.add(new JButton(new AbstractAction("Start") { @Override public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override public Void doInBackground() { int current = 0, lengthOfTask = 100; while (current <= lengthOfTask && !isCancelled()) { try { Thread.sleep(50); } catch (Exception ie) { return null; } setProgress(100 * current / lengthOfTask); current++; } return null; } }; worker.addPropertyChangeListener(new ProgressListener(progressBar)); worker.execute(); } })); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(p); frame.setSize(320, 240); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextArea cmp = new JTextArea(); String str = "a"; for (int i = 0; i < 20; i++) { cmp.append(str + str + "\n"); }//from w w w . j ava 2 s . c o m JScrollPane scrollPane = new JScrollPane(cmp); scrollPane.setComponentZOrder(scrollPane.getVerticalScrollBar(), 0); scrollPane.setComponentZOrder(scrollPane.getViewport(), 1); scrollPane.getVerticalScrollBar().setOpaque(false); scrollPane.setLayout(new ScrollPaneLayout() { @Override public void layoutContainer(Container parent) { JScrollPane scrollPane = (JScrollPane) parent; Rectangle availR = scrollPane.getBounds(); availR.x = availR.y = 0; Insets parentInsets = parent.getInsets(); availR.x = parentInsets.left; availR.y = parentInsets.top; availR.width -= parentInsets.left + parentInsets.right; availR.height -= parentInsets.top + parentInsets.bottom; Rectangle vsbR = new Rectangle(); vsbR.width = 12; vsbR.height = availR.height; vsbR.x = availR.x + availR.width - vsbR.width; vsbR.y = availR.y; if (viewport != null) { viewport.setBounds(availR); } if (vsb != null) { vsb.setVisible(true); vsb.setBounds(vsbR); } } }); scrollPane.getVerticalScrollBar().setUI(new MyScrollBarUI()); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(scrollPane); f.setSize(320, 240); f.setVisible(true); }
From source file:com.jgoodies.validation.tutorial.formatted.NumberExample.java
public static void main(String[] args) { try {/* www .j a va 2s .c o m*/ UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); } catch (Exception e) { // Likely Plastic is not in the classpath; ignore it. } JFrame frame = new JFrame(); frame.setTitle("Formatted :: Numbers"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComponent panel = new NumberExample().buildPanel(); frame.getContentPane().add(panel); frame.pack(); TutorialUtils.locateOnScreenCenter(frame); frame.setVisible(true); }
From source file:com.jgoodies.validation.tutorial.formatted.DateExample.java
public static void main(String[] args) { try {/*from w w w. j av a 2 s . c om*/ UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); } catch (Exception e) { // Likely Plastic is not in the classpath; ignore it. } JFrame frame = new JFrame(); frame.setTitle("Formatted :: Dates"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComponent panel = new DateExample().buildPanel(); frame.getContentPane().add(panel); frame.pack(); TutorialUtils.locateOnScreenCenter(frame); frame.setVisible(true); }
From source file:acmi.l2.clientmod.l2_version_switcher.Main.java
public static void main(String[] args) { if (args.length != 3 && args.length != 4) { System.out.println("USAGE: l2_version_switcher.jar host game version <--splash> <filter>"); System.out.println("EXAMPLE: l2_version_switcher.jar " + L2.NCWEST_HOST + " " + L2.NCWEST_GAME + " 1 \"system\\*\""); System.out.println(/*from w w w . j ava 2 s. com*/ " l2_version_switcher.jar " + L2.PLAYNC_TEST_HOST + " " + L2.PLAYNC_TEST_GAME + " 48"); System.exit(0); } List<String> argsList = new ArrayList<>(Arrays.asList(args)); String host = argsList.get(0); String game = argsList.get(1); int version = Integer.parseInt(argsList.get(2)); Helper helper = new Helper(host, game, version); boolean available = false; try { available = helper.isAvailable(); } catch (IOException e) { System.err.print(e.getClass().getSimpleName()); if (e.getMessage() != null) { System.err.print(": " + e.getMessage()); } System.err.println(); } System.out.println(String.format("Version %d available: %b", version, available)); if (!available) { System.exit(0); } List<FileInfo> fileInfoList = null; try { fileInfoList = helper.getFileInfoList(); } catch (IOException e) { System.err.println("Couldn\'t get file info map"); System.exit(1); } boolean splash = argsList.remove("--splash"); if (splash) { Optional<FileInfo> splashObj = fileInfoList.stream() .filter(fi -> fi.getPath().contains("sp_32b_01.bmp")).findAny(); if (splashObj.isPresent()) { try (InputStream is = new FilterInputStream( Util.getUnzipStream(helper.getDownloadStream(splashObj.get().getPath()))) { @Override public int read() throws IOException { int b = super.read(); if (b >= 0) b ^= 0x36; return b; } @Override public int read(byte[] b, int off, int len) throws IOException { int r = super.read(b, off, len); if (r >= 0) { for (int i = 0; i < r; i++) b[off + i] ^= 0x36; } return r; } }) { new DataInputStream(is).readFully(new byte[28]); BufferedImage bi = ImageIO.read(is); JFrame frame = new JFrame("Lineage 2 [" + version + "] " + splashObj.get().getPath()); frame.setContentPane(new JComponent() { { setPreferredSize(new Dimension(bi.getWidth(), bi.getHeight())); } @Override protected void paintComponent(Graphics g) { g.drawImage(bi, 0, 0, null); } }); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } catch (IOException e) { e.printStackTrace(); } } else { System.out.println("Splash not found"); } return; } String filter = argsList.size() > 3 ? separatorsToSystem(argsList.get(3)) : null; File l2Folder = new File(System.getProperty("user.dir")); List<FileInfo> toUpdate = fileInfoList.parallelStream().filter(fi -> { String filePath = separatorsToSystem(fi.getPath()); if (filter != null && !wildcardMatch(filePath, filter, IOCase.INSENSITIVE)) return false; File file = new File(l2Folder, filePath); try { if (file.exists() && file.length() == fi.getSize() && Util.hashEquals(file, fi.getHash())) { System.out.println(filePath + ": OK"); return false; } } catch (IOException e) { System.out.println(filePath + ": couldn't check hash: " + e); return true; } System.out.println(filePath + ": need update"); return true; }).collect(Collectors.toList()); List<String> errors = Collections.synchronizedList(new ArrayList<>()); ExecutorService executor = Executors.newFixedThreadPool(16); CompletableFuture[] tasks = toUpdate.stream().map(fi -> CompletableFuture.runAsync(() -> { String filePath = separatorsToSystem(fi.getPath()); File file = new File(l2Folder, filePath); File folder = file.getParentFile(); if (!folder.exists()) { if (!folder.mkdirs()) { errors.add(filePath + ": couldn't create parent dir"); return; } } try (InputStream input = Util .getUnzipStream(new BufferedInputStream(helper.getDownloadStream(fi.getPath()))); OutputStream output = new BufferedOutputStream(new FileOutputStream(file))) { byte[] buffer = new byte[Math.min(fi.getSize(), 1 << 24)]; int pos = 0; int r; while ((r = input.read(buffer, pos, buffer.length - pos)) >= 0) { pos += r; if (pos == buffer.length) { output.write(buffer, 0, pos); pos = 0; } } if (pos != 0) { output.write(buffer, 0, pos); } System.out.println(filePath + ": OK"); } catch (IOException e) { String msg = filePath + ": FAIL: " + e.getClass().getSimpleName(); if (e.getMessage() != null) { msg += ": " + e.getMessage(); } errors.add(msg); } }, executor)).toArray(CompletableFuture[]::new); CompletableFuture.allOf(tasks).thenRun(() -> { for (String err : errors) System.err.println(err); executor.shutdown(); }); }
From source file:emperior.Main.java
public static void main(String[] args) throws Exception { mainFrame = new MainFrame(); operatingSystem = System.getProperty("os.name"); CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "help", false, "Print this usage information"); options.addOption("t", "test", true, "Name of the Bat-File which is executed for Compilation and Unit-Testing"); options.addOption("r", "run", true, "Name of the Bat-File which is executed for Compilation and running the project"); options.addOption("f", "folder", true, "Name of the Folder in which the exercises for the Experiment are stored"); CommandLine commandLine = parser.parse(options, args); // read from command line if (commandLine.getOptions().length > 0) { readCommandLine(commandLine, options); }//from w ww .jav a 2 s . c o m // read from property file else { readPropertyFile(); } initLogging(); checkBatFile(); addLineToLogFile("[Start] Emperior"); if (resuming) Main.addLineToLogFile("[ResumeTask] Resume task: " + Main.tasktypes.get(Main.activeType) + "_" + Main.tasks.get(Main.activeTask)); else { Main.addLineToLogFile("[StartTask] Start new task: " + Main.tasktypes.get(Main.activeType) + "_" + Main.tasks.get(Main.activeTask)); startedWith = Main.tasktypes.get(Main.activeType) + "_" + Main.tasks.get(Main.activeTask); updateStartedWithTask(Main.tasktypes.get(Main.activeType) + "_" + Main.tasks.get(Main.activeTask)); } mainFrame.init(); mainFrame.setSize(800, 600); mainFrame.setVisible(true); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { Main.addLineToLogFile("[PauseTask] Stop task: " + Main.tasktypes.get(Main.activeType) + "_" + Main.tasks.get(Main.activeTask)); addLineToLogFile("[Close] Emperior"); updateResumeTask(tasktypes.get(activeType) + "_" + tasks.get(activeTask)); System.exit(0); } }); mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); //makeContiniousCopys(); }
From source file:net.sf.jsignpdf.Signer.java
/** * Main.//from w w w . j a v a2 s. c om * * @param args */ public static void main(String[] args) { SignerOptionsFromCmdLine tmpOpts = null; if (args != null && args.length > 0) { tmpOpts = new SignerOptionsFromCmdLine(); parseCommandLine(args, tmpOpts); } try { SSLInitializer.init(); } catch (Exception e) { LOGGER.warn("Unable to re-configure SSL layer", e); } pkcs11ProviderName = PKCS11Utils .registerProvider(ConfigProvider.getInstance().getProperty("pkcs11config.path")); traceInfo(); if (tmpOpts != null) { if (tmpOpts.isPrintVersion()) { System.out.println("JSignPdf version " + VERSION); } if (tmpOpts.isPrintHelp()) { printHelp(); } if (tmpOpts.isListKeyStores()) { LOGGER.info(RES.get("console.keystores")); for (String tmpKsType : KeyStoreUtils.getKeyStores()) { System.out.println(tmpKsType); } } if (tmpOpts.isListKeys()) { final String[] tmpKeyAliases = KeyStoreUtils.getKeyAliases(tmpOpts); LOGGER.info(RES.get("console.keys")); // list certificate aliases in the keystore for (String tmpCert : tmpKeyAliases) { System.out.println(tmpCert); } } if (ArrayUtils.isNotEmpty(tmpOpts.getFiles()) || (!StringUtils.isEmpty(tmpOpts.getInFile()) && !StringUtils.isEmpty(tmpOpts.getOutFile()))) { signFiles(tmpOpts); } else { final boolean tmpCommand = tmpOpts.isPrintVersion() || tmpOpts.isPrintHelp() || tmpOpts.isListKeyStores() || tmpOpts.isListKeys(); if (!tmpCommand) { // no valid command provided - print help and exit printHelp(); exit(EXIT_CODE_NO_COMMAND); } } exit(0); } else { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { System.err.println("Can't set Look&Feel."); } SignPdfForm tmpForm = new SignPdfForm(WindowConstants.EXIT_ON_CLOSE); tmpForm.pack(); GuiUtils.center(tmpForm); tmpForm.setVisible(true); } }
From source file:jp.massbank.spectrumsearch.SearchPage.java
public static void main(String[] args) { LOGGER.info("Application start!"); LOGGER.info("Spectrum Search version " + SearchPage.class.getPackage().getImplementationVersion()); SearchPage appli = new SearchPage(); appli.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); appli.setTitle(APPLICATION_TITLE);/*from w w w . j a va2 s . c o m*/ appli.setSize(1200, 700); try { appli.init(); appli.setVisible(true); } catch (SQLException e) { LOGGER.error(e.getMessage(), e); System.exit(-1); } }