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

License:asdf

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        System.out.println("SystemTray is not supported");
        return;/*from w  ww  . j a v  a 2s  .  c o m*/
    }

    SystemTray tray = SystemTray.getSystemTray();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image = toolkit.getImage("trayIcon.jpg");

    PopupMenu menu = new PopupMenu();

    MenuItem messageItem = new MenuItem("Show Message");
    messageItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("asdf");
        }
    });
    menu.add(messageItem);

    MenuItem closeItem = new MenuItem("Close");
    closeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    menu.add(closeItem);
    TrayIcon icon = new TrayIcon(image, "SystemTray Demo", menu);
    icon.setImageAutoSize(true);

    tray.add(icon);
}

From source file:Main.java

License:asdf

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        System.out.println("SystemTray is not supported");
        return;/*from  ww w .  ja  v  a  2s  .  c  o m*/
    }

    SystemTray tray = SystemTray.getSystemTray();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image = toolkit.getImage("trayIcon.jpg");

    PopupMenu menu = new PopupMenu();

    MenuItem messageItem = new MenuItem("Show Message");
    messageItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("asdf");
        }
    });
    menu.add(messageItem);

    MenuItem closeItem = new MenuItem("Close");
    closeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    menu.add(closeItem);
    TrayIcon icon = new TrayIcon(image, "SystemTray Demo", menu);
    icon.setImageAutoSize(true);

    icon.setToolTip("tooltip");
    tray.add(icon);
}

From source file:Main.java

License:asdf

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        System.out.println("SystemTray is not supported");
        return;//from  w w  w.j  a  v  a  2  s.  c o m
    }

    SystemTray tray = SystemTray.getSystemTray();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image = toolkit.getImage("trayIcon.jpg");

    PopupMenu menu = new PopupMenu();

    MenuItem messageItem = new MenuItem("Show Message");
    messageItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("asdf");
        }
    });
    menu.add(messageItem);

    MenuItem closeItem = new MenuItem("Close");
    closeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    menu.add(closeItem);
    TrayIcon icon = new TrayIcon(image, "SystemTray Demo", menu);
    icon.setImageAutoSize(true);

    image = toolkit.getImage("anotherImage.jpg");
    icon.setImage(image);
    tray.add(icon);
}

From source file:AddingAWTImagePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from ww  w.j  a  va2 s  . c  o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddingAWTImagePDF.pdf"));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage("logo.png");
        Image image = Image.getInstance(awtImage, null);
        image.setAbsolutePosition(100, 500);
        cb.addImage(image);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:MainClass.java

public static void main(String args[]) {
    // void copyToClipboard() {
    String toClipboard = "Hello from Java!";
    StringSelection ss = new StringSelection(toClipboard);
    Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    clip.setContents(ss, ss);/*from ww  w  .  ja  va  2  s  . c om*/
    // Paste
    clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable contents = clip.getContents(new MainClass().getClass());
    if (contents == null)
        System.out.println("The clipboard is empty.");
    else {
        if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            try {
                String data = (String) contents.getTransferData(DataFlavor.stringFlavor);
                if (data == null)
                    System.out.println("null");
                else {
                    StringTokenizer st = new StringTokenizer(data, "\n");
                    while (st.hasMoreElements())
                        System.out.println(st.nextToken());
                }
            } 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[] args) throws Exception {
    Robot robot = new Robot();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    BufferedImage screen = robot.createScreenCapture(new Rectangle(screenSize));

    new ScreenCaptureRectangle(screen);
}

From source file:SystemTrayDemo.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        System.out.println("SystemTray is not supported");
        return;/*  w  ww .  j  a  v a  2  s  .  c o m*/
    }

    SystemTray tray = SystemTray.getSystemTray();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image = toolkit.getImage("trayIcon.jpg");

    PopupMenu menu = new PopupMenu();

    MenuItem messageItem = new MenuItem("Show Message");
    messageItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "www.java2s.com");
        }
    });
    menu.add(messageItem);

    MenuItem closeItem = new MenuItem("Close");
    closeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    menu.add(closeItem);
    TrayIcon icon = new TrayIcon(image, "SystemTray Demo", menu);
    icon.setImageAutoSize(true);

    tray.add(icon);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_PRINTSCREEN);
    robot.delay(40);/*from w  w w .  j  av a  2 s  . c om*/
    robot.keyRelease(KeyEvent.VK_PRINTSCREEN);
    robot.delay(404);

    Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
    DataFlavor[] flavors = cb.getAvailableDataFlavors();
    for (DataFlavor flavor : flavors) {
        if (flavor.toString().indexOf("java.awt.Image") <= 0) {
            continue;
        }
        Image i = (Image) cb.getData(flavor);
        BufferedImage bi = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_RGB);
        Graphics2D g = bi.createGraphics();
        g.drawImage(i, 0, 0, null);
        g.dispose();
        ImageIO.write(bi, "png", new File("c:/Java_Dev/test.png"));
    }
}

From source file:AddingAWTImageColorPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*w  w w.  ja  v  a 2s . com*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddingAWTImageColorPDF.pdf"));
        document.open();
        PdfContentByte cb = writer.getDirectContent();

        java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage("logo.png");

        Image image = Image.getInstance(awtImage, new Color(0x00, 0x00, 0xFF), true);
        image.setAbsolutePosition(100, 500);
        cb.addImage(image);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String mapUrlPath = "http://www.java2s.com/style/download.png";
    URL mapUrl = new URL(mapUrlPath);
    BufferedImage mapImage = ImageIO.read(mapUrl);
    Image newMapImage = Toolkit.getDefaultToolkit()
            .createImage(new FilteredImageSource(mapImage.getSource(), new RedBlueSwapFilter()));
    ImageIcon mapIcon = new ImageIcon(mapImage);
    ImageIcon newMapIcon = new ImageIcon(newMapImage);

    JPanel imagePanel = new JPanel();
    imagePanel.add(new JLabel(mapIcon));
    imagePanel.add(new JLabel(newMapIcon));

    JOptionPane.showMessageDialog(null, imagePanel);
}