List of usage examples for java.awt Toolkit getDefaultToolkit
public static synchronized Toolkit getDefaultToolkit()
From source file:Jpeg.java
public static void main(String args[]) { Image image = null;/*from w w w.j a v a 2s . co m*/ FileOutputStream dataOut = null; File file, outFile; JpegEncoder jpg; String string = ""; int i, Quality = 80; // Check to see if the input file name has one of the extensions: // .tif, .gif, .jpg // If not, print the standard use info. if (args.length < 2) StandardUsage(); if (!args[0].endsWith(".jpg") && !args[0].endsWith(".tif") && !args[0].endsWith(".gif")) StandardUsage(); // First check to see if there is an OutputFile argument. If there isn't // then name the file "InputFile".jpg // Second check to see if the .jpg extension is on the OutputFile argument. // If there isn't one, add it. // Need to check for the existence of the output file. If it exists already, // rename the file with a # after the file name, then the .jpg extension. if (args.length < 3) { string = args[0].substring(0, args[0].lastIndexOf(".")) + ".jpg"; } else { string = args[2]; if (string.endsWith(".tif") || string.endsWith(".gif")) string = string.substring(0, string.lastIndexOf(".")); if (!string.endsWith(".jpg")) string = string.concat(".jpg"); } outFile = new File(string); i = 1; while (outFile.exists()) { outFile = new File(string.substring(0, string.lastIndexOf(".")) + (i++) + ".jpg"); if (i > 100) System.exit(0); } file = new File(args[0]); if (file.exists()) { try { dataOut = new FileOutputStream(outFile); } catch (IOException e) { } try { Quality = Integer.parseInt(args[1]); } catch (NumberFormatException e) { StandardUsage(); } image = Toolkit.getDefaultToolkit().getImage(args[0]); jpg = new JpegEncoder(image, Quality, dataOut); jpg.Compress(); try { dataOut.close(); } catch (IOException e) { } } else { System.out.println("I couldn't find " + args[0] + ". Is it in another directory?"); } System.exit(0); }
From source file:com.willwinder.universalgcodesender.ExperimentalWindow.java
/** * @param args the command line arguments *//*from w ww. j a v a2 s. c om*/ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> // Fix look and feel to use CMD+C/X/V/A instead of CTRL if (SystemUtils.IS_OS_MAC) { Collection<InputMap> ims = new ArrayList<>(); ims.add((InputMap) UIManager.get("TextField.focusInputMap")); ims.add((InputMap) UIManager.get("TextArea.focusInputMap")); ims.add((InputMap) UIManager.get("EditorPane.focusInputMap")); ims.add((InputMap) UIManager.get("FormattedTextField.focusInputMap")); ims.add((InputMap) UIManager.get("PasswordField.focusInputMap")); ims.add((InputMap) UIManager.get("TextPane.focusInputMap")); int c = KeyEvent.VK_C; int v = KeyEvent.VK_V; int x = KeyEvent.VK_X; int a = KeyEvent.VK_A; int meta = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); for (InputMap im : ims) { im.put(KeyStroke.getKeyStroke(c, meta), DefaultEditorKit.copyAction); im.put(KeyStroke.getKeyStroke(v, meta), DefaultEditorKit.pasteAction); im.put(KeyStroke.getKeyStroke(x, meta), DefaultEditorKit.cutAction); im.put(KeyStroke.getKeyStroke(a, meta), DefaultEditorKit.selectAllAction); } } /* Create the form */ // GUIBackend backend = new GUIBackend(); final ExperimentalWindow mw = new ExperimentalWindow(); /* Apply the settings to the ExperimentalWindow bofore showing it */ mw.setSize(mw.backend.getSettings().getMainWindowSettings().width, mw.backend.getSettings().getMainWindowSettings().height); mw.setLocation(mw.backend.getSettings().getMainWindowSettings().xLocation, mw.backend.getSettings().getMainWindowSettings().yLocation); mw.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent ce) { mw.backend.getSettings().getMainWindowSettings().height = ce.getComponent().getSize().height; mw.backend.getSettings().getMainWindowSettings().width = ce.getComponent().getSize().width; } @Override public void componentMoved(ComponentEvent ce) { mw.backend.getSettings().getMainWindowSettings().xLocation = ce.getComponent().getLocation().x; mw.backend.getSettings().getMainWindowSettings().yLocation = ce.getComponent().getLocation().y; } @Override public void componentShown(ComponentEvent ce) { } @Override public void componentHidden(ComponentEvent ce) { } }); /* Display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { mw.setVisible(true); } }); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { mw.connectionPanel.saveSettings(); mw.commandPanel.saveSettings(); if (mw.pendantUI != null) { mw.pendantUI.stop(); } } }); }
From source file:MessageMonitor.java
/** Main program entry point. */ public static void main(String[] args) { // There should be no arguments to this program. if (args.length > 0) { printUsage();//w w w . j av a2 s .com System.exit(1); } MessageMonitor messageMonitor = new MessageMonitor(); messageMonitor.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); screenSize.height = screenSize.height / 2; screenSize.width = screenSize.width / 2; messageMonitor.setSize(screenSize); messageMonitor.setVisible(true); }
From source file:Main.java
public static void main() { JFrame frame = new JFrame(); Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif"); frame.setIconImage(icon);/*from w ww.j a v a2s .c o m*/ }
From source file:Main.java
public static Dimension getScreenSize() { Toolkit tk = Toolkit.getDefaultToolkit(); return tk.getScreenSize(); }
From source file:Main.java
public static int getScreenHeight() { Dimension screenSz = Toolkit.getDefaultToolkit().getScreenSize(); return screenSz.height; }
From source file:Main.java
public static Point getCenterPoint() { Toolkit toolkit = Toolkit.getDefaultToolkit(); double desktopHeight = toolkit.getScreenSize().getHeight(); double desktopWidth = toolkit.getScreenSize().getWidth(); return new Point((int) desktopWidth / 2, (int) desktopHeight / 2); }
From source file:Main.java
public static void copyStringToClipboard(String string) { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(string), null); }
From source file:Main.java
public static Dimension getDefaultMainFrameSize() { Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); size.width = size.width * 8 / 10;/*from ww w . ja v a 2s . c o m*/ size.height = size.height * 8 / 10; return size; }
From source file:Main.java
public static void setFrameCenter(JFrame frame) { int screenWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth(); int screenHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight(); frame.setLocation((screenWidth - frame.getWidth()) / 2, (screenHeight - frame.getHeight()) / 2); }