List of usage examples for java.awt Toolkit getDefaultToolkit
public static synchronized Toolkit getDefaultToolkit()
From source file:Main.java
public Main() { try {/*from w ww . j a v a 2s . c o m*/ robot = new Robot(); } catch (Exception e1) { e1.printStackTrace(); } timer = new Timer(3000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Rectangle size = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); Image image = robot.createScreenCapture(size); label.setIcon(new ImageIcon(image)); frame.setVisible(true); } }); timer.setRepeats(false); button.addActionListener(e -> { frame.setVisible(false); timer.start(); }); frame.add(button, BorderLayout.NORTH); frame.add(label, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(1024, 768); frame.setVisible(true); }
From source file:net.chaosserver.timelord.swingui.SwingUtil.java
/** * Repair location is designed to detect if a box is partially * off-screen and move the box back onto the screen. * * @param component component to repair/*from w w w . ja v a 2s . c o m*/ */ public static void repairLocation(Component component) { Point locationPoint = component.getLocation(); Point locationOnScreenPoint = null; if (component.isVisible()) { locationOnScreenPoint = component.getLocationOnScreen(); } Dimension componentSize = component.getSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); if (log.isDebugEnabled()) { log.debug("Repairing location on [" + component.getClass().getName() + "]. Original location point = [" + locationPoint + "] and location on screen point = [" + locationOnScreenPoint + "]. The screen size is [" + screenSize + "] and the component size is [" + componentSize + "]"); } // Is the dialog to far to the left? Then fix. if (locationPoint.getX() < 0) { locationPoint.setLocation(0, locationPoint.getY()); } if (locationPoint.getY() < 0) { locationPoint.setLocation(locationPoint.getX(), 0); } // component.setLocation(locationPoint); // Is the dialog too wide? if (locationPoint.getX() + componentSize.getWidth() > screenSize.getWidth()) { componentSize.width = (int) (screenSize.getWidth() - locationPoint.getX()); } if (locationPoint.getY() + componentSize.getHeight() > screenSize.getHeight()) { componentSize.height = (int) (screenSize.getHeight() - locationPoint.getY()); } // component.setSize(componentSize); }
From source file:Main.java
public Point getClick() { EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); while (true) { try {// ww w . j ava2 s. c o m AWTEvent evt = eq.getNextEvent(); if (evt.getID() == MouseEvent.MOUSE_PRESSED) { MouseEvent mevt = (MouseEvent) evt; Point p = mevt.getPoint(); Point top = getRootPane().getLocation(); p.x -= top.x; p.y -= top.y; return p; } } catch (InterruptedException e) { } } }
From source file:Main.java
public Point getClick() { EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); System.out.println(eq.isDispatchThread()); while (true) { try {/* w w w . ja v a 2s. c om*/ AWTEvent evt = eq.getNextEvent(); if (evt.getID() == MouseEvent.MOUSE_PRESSED) { MouseEvent mevt = (MouseEvent) evt; Point p = mevt.getPoint(); Point top = getRootPane().getLocation(); p.x -= top.x; p.y -= top.y; return p; } } catch (InterruptedException e) { } } }
From source file:Main.java
public Point getClick() { EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); while (true) { try {/*from w w w .ja v a 2 s. c om*/ AWTEvent pEvent = eq.peekEvent(); AWTEvent evt = eq.getNextEvent(); if (evt.getID() == MouseEvent.MOUSE_PRESSED) { MouseEvent mevt = (MouseEvent) evt; Point p = mevt.getPoint(); Point top = getRootPane().getLocation(); p.x -= top.x; p.y -= top.y; return p; } } catch (InterruptedException e) { } } }
From source file:Main.java
/** * Updates the passed window's position to center it with respect to the * screen. May be called before or after the window is made visible (but * remember to call <code>pack()</code> first!). * <p>//from ww w.ja v a2 s .c o m * Deals with multi-monitor setups via the following hack: if the screen * size reported by the default toolkit has a width:height ration > 2:1, * then the width is divided by 2. This works well for 1, 2, or 3 screen * desktops: the window will appear in the left screen of a 2-screen * setup, in the middle of a 3-screen setup. * <p> * If the window is larger than the screen size, it's positioned at the * top-left corner. Hopefully the user will be able to shrink it. */ public static void center(Window window) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int width = screenSize.width; int height = screenSize.height; if (width > height * 2) { width /= 2; } center(window, new Rectangle(0, 0, width, height), false); }
From source file:mergedoc.Application.java
/** * ? Look & Feel ???/*from w ww . j a va 2s . c o m*/ * @throws ClassNotFoundException LookAndFeel ???????? * @throws InstantiationException ???????????? * @throws IllegalAccessException ???????????? * @throws UnsupportedLookAndFeelException lnf.isSupportedLookAndFeel() ? false ?? */ private static void initSystemLookAndFeel() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); Toolkit.getDefaultToolkit().setDynamicLayout(true); // Windows ??? String osName = System.getProperty("os.name", ""); if (osName.indexOf("Windows") != -1) { Object propoFont = new FontUIResource("MS UI Gothic", Font.PLAIN, 12); Object fixedFont = new FontUIResource("MS Gothic", Font.PLAIN, 12); // ?????????? // ????? instanceof FontUIResource ? // ???UIDefaults ? Lazy Value ?????? for (Object keyObj : UIManager.getLookAndFeelDefaults().keySet()) { String key = keyObj.toString(); if (key.endsWith("font") || key.endsWith("Font")) { UIManager.put(key, propoFont); } } // ????? UIManager.put("OptionPane.messageFont", fixedFont); UIManager.put("TextPane.font", fixedFont); UIManager.put("TextArea.font", fixedFont); } }
From source file:LabelJarSample.java
public static Image getImage(Class relativeClass, String filename) { Image returnValue = null;// w w w.j a v a 2s . c o m InputStream is = relativeClass.getResourceAsStream(filename); if (is != null) { BufferedInputStream bis = new BufferedInputStream(is); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { int ch; while ((ch = bis.read()) != -1) { baos.write(ch); } returnValue = Toolkit.getDefaultToolkit().createImage(baos.toByteArray()); } catch (IOException exception) { System.err.println("Error loading: " + filename); } } return returnValue; }
From source file:Test.java
public ApplicationWindow() { this.setSize(200, 100); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new FlowLayout()); JButton exitButton = new JButton("Exit"); this.add(exitButton); int totalButtons = MouseInfo.getNumberOfButtons(); System.out.println(Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()); System.out.println("You have " + totalButtons + " total buttons"); this.addMouseListener(this); this.addMouseWheelListener(this); exitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0);/* w w w .java2s. c om*/ } }); }
From source file:Main.java
public void actionPerformed(ActionEvent e) { String file = "a.png"; if (file != null) { Toolkit kit = Toolkit.getDefaultToolkit(); img = kit.getImage(file);// w ww .jav a2 s .c o m img = img.getScaledInstance(300, -1, Image.SCALE_SMOOTH); this.repaint(); } }