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[] argv) throws Exception {
    Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);

    if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
        Image img = (Image) t.getTransferData(DataFlavor.imageFlavor);
    }/*from w  w  w .  jav a2  s  . c  o m*/
}

From source file:Main.java

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

    String imgName = "image.jpg";
    URL imgURL = Main.class.getResource(imgName);
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image img = tk.getImage(imgURL);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable tran = clipboard.getContents(null);

    if (tran != null && tran.isDataFlavorSupported(DataFlavor.stringFlavor)) {

        String clipboardContent = (String) tran.getTransferData(DataFlavor.stringFlavor);

        System.out.println(clipboardContent);
    }/*from   w ww.j a  v  a2  s.  c  o m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_3BYTE_BGR);
    Image img = Toolkit.getDefaultToolkit().createImage(bufferedImage.getSource());
}

From source file:Main.java

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

    int[] pixels = new int[16 * 16];
    Image image = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(16, 16, pixels, 0, 16));
    Cursor transparentCursor = Toolkit.getDefaultToolkit().createCustomCursor(image, new Point(0, 0),
            "invisibleCursor");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection testData = new StringSelection("Test Data");

    c.setContents(testData, testData);/*from   w  ww.j  ava  2  s.c o  m*/
    // Get clipboard contents, as a String
    Transferable t = c.getContents(null);
    if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        Object o = t.getTransferData(DataFlavor.stringFlavor);
        String data = (String) t.getTransferData(DataFlavor.stringFlavor);
        System.out.println("Clipboard contents: " + data);
    }
    System.exit(0);
}

From source file:MainClass.java

public static void main(String args[]) {
    Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    System.out.println("Object Name: " + clip.getName());
    Transferable contents = clip.getContents(new MainClass().getClass());
    if (contents == null)
        System.out.println("\n\nThe clipboard is empty.");
    else {/*from w  w  w.j a va  2 s.co m*/
        DataFlavor flavors[] = contents.getTransferDataFlavors();
        for (int i = 0; i < flavors.length; ++i) {
            System.out.println("\n\n Name: " + flavors[i].getHumanPresentableName());
            System.out.println("\n MIME Type: " + flavors[i].getMimeType());
            Class cl = flavors[i].getRepresentationClass();
            if (cl == null)
                System.out.println("null");
            else
                System.out.println(cl.getName());
        }
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Image image = Toolkit.getDefaultToolkit().getImage("inFile.png");

    PixelGrabber grabber = new PixelGrabber(image, 0, 0, -1, -1, false);

    if (grabber.grabPixels()) {
        int width = grabber.getWidth();
        int height = grabber.getHeight();
        if (isGreyscaleImage(grabber)) {
            byte[] data = (byte[]) grabber.getPixels();
        } else {/*from   w  w w  . j  ava2 s. co  m*/
            int[] data = (int[]) grabber.getPixels();
        }
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    String name = "Test print job";
    Properties properties = new Properties();
    PrintJob pj = Toolkit.getDefaultToolkit().getPrintJob(new MainClass(), name, properties);
    if (pj != null) {
        printDimensions(pj.getGraphics(), pj.getPageDimension());
        pj.end();/*from  w  w w .ja  v  a 2  s.  c  o m*/
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame frm = new JFrame("Main");
    Image im = Toolkit.getDefaultToolkit().getImage("c:\\icons\\icon1.png");
    TrayIcon tri = new TrayIcon(im);
    tri.addActionListener(e -> {//from  w w  w  . ja va2 s  . c  o  m
        frm.setVisible(true);
        try {
            SystemTray.getSystemTray().remove(tri);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    });
    frm.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            try {
                SystemTray.getSystemTray().add(tri);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            frm.setVisible(false);
        }
    });
    frm.setSize(100, 100);
    frm.setVisible(true);
}