Example usage for java.awt Toolkit getDefaultToolkit

List of usage examples for java.awt Toolkit getDefaultToolkit

Introduction

In this page you can find the example usage for java.awt Toolkit getDefaultToolkit.

Prototype

public static synchronized Toolkit getDefaultToolkit() 

Source Link

Document

Gets the default toolkit.

Usage

From source file:Main.java

public static void main(String[] arg) throws Exception {
    Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    Robot robot = new Robot();

    BufferedImage image = robot//from  w  w w  . j  a va 2 s .c  om
            .createScreenCapture(new Rectangle(0, 0, (int) screenDim.getWidth(), (int) screenDim.getHeight()));

    JWindow window = new JWindow(new JFrame());
    window.getContentPane().setLayout(new BorderLayout());
    window.getContentPane().add(BorderLayout.CENTER, new JLabel(new ImageIcon(image)));
    window.pack();
    window.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ClipboardOwner owner = new MyClipboardOwner();

    StringSelection ss = new StringSelection("A String");
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, owner);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    InputStream is = Main.class.getResourceAsStream("image.gif");
    BufferedInputStream bis = new BufferedInputStream(is);
    byte[] byBuf = new byte[10000];

    int byteRead = bis.read(byBuf, 0, 10000);
    Image img = Toolkit.getDefaultToolkit().createImage(byBuf);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    ImageSelection imgSel = new ImageSelection(new ImageIcon("a.png").getImage());
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imgSel, null);
}

From source file:Capture.java

public static void main(String[] args) {
    JFrame capture = new JFrame();
    capture.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Toolkit kit = Toolkit.getDefaultToolkit();
    final Dimension d = kit.getScreenSize();
    capture.setSize(d);/*  www. j a v  a2s  .c  o  m*/

    Rectangle rect = new Rectangle(d);
    try {
        Robot robot = new Robot();
        final BufferedImage image = robot.createScreenCapture(rect);
        image.flush();
        JPanel panel = new JPanel() {
            public void paintComponent(Graphics g) {
                g.drawImage(image, 0, 0, d.width, d.height, this);
            }
        };
        panel.setOpaque(false);
        panel.prepareImage(image, panel);
        panel.repaint();
        capture.getContentPane().add(panel);
    } catch (Exception e) {
        e.printStackTrace();
    }

    capture.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    BufferedImage image = robot.createScreenCapture(new Rectangle(d));
    BufferedImage sub = image.getSubimage(0, 0, 400, 400);
    File f = new File("SubImage.png");
    ImageIO.write(sub, "png", f);
    final ImageIcon im = new ImageIcon(f.toURI().toURL());

    Runnable r = new Runnable() {

        @Override//  ww  w  .j a v  a  2 s .com
        public void run() {
            JOptionPane.showMessageDialog(null, new JLabel(im));
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Robot robot = new Robot();
    int x = 100;//from w  w w  . j  av a 2 s  .c o  m
    int y = 100;
    int width = 200;
    int height = 200;
    Rectangle area = new Rectangle(x, y, width, height);
    BufferedImage bufferedImage = robot.createScreenCapture(area);

    area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    bufferedImage = robot.createScreenCapture(area);
}

From source file:Main.java

public static void main(String args[]) {
    String toClipboard = "Hello from Java!";
    StringSelection ss = new StringSelection(toClipboard);
    Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    clip.setContents(ss, ss);//from  ww w .ja v a  2 s. c  om
    clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable contents = clip.getContents(new Main().getClass());
    if (contents == null) {
        System.out.println("The clipboard is empty.");
        return;
    }
    if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            String data = (String) contents.getTransferData(DataFlavor.stringFlavor);
            System.out.println(data);
        } catch (IOException ex) {
            System.out.println("IOException");
        } catch (UnsupportedFlavorException ex) {
            System.out.println("UnsupportedFlavorException");
        }
    } else {
        System.out.println("Wrong flavor.");
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Robot robot = new Robot();
    int x = 100;//from   w  w w  . j a  v a2s.c o  m
    int y = 100;
    int width = 200;
    int height = 200;
    Rectangle area = new Rectangle(x, y, width, height);
    BufferedImage bufferedImage = robot.createScreenCapture(area);

    // Capture the whole screen
    area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    bufferedImage = robot.createScreenCapture(area);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ResultSet rset = null;/*from  ww  w  .  ja  va2 s . com*/
    InputStream stream = rset.getBinaryStream(1);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    int a1 = stream.read();
    while (a1 >= 0) {
        output.write((char) a1);
        a1 = stream.read();
    }
    Image myImage = Toolkit.getDefaultToolkit().createImage(output.toByteArray());
    output.close();

}