Example usage for java.awt Toolkit getImage

List of usage examples for java.awt Toolkit getImage

Introduction

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

Prototype

public abstract Image getImage(URL url);

Source Link

Document

Returns an image which gets pixel data from the specified URL.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Toolkit t = Toolkit.getDefaultToolkit();
    Image im = t.getImage("C:/Java/image.PNG");

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("image address");
    Toolkit t = Toolkit.getDefaultToolkit();
    Image im = t.getImage(url);

}

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:MainClass.java

public static void main(String[] args) {
    ImageObserver myObserver = new ImageObserver() {
        public boolean imageUpdate(Image image, int flags, int x, int y, int width, int height) {
            if ((flags & HEIGHT) != 0)
                System.out.println("Image height = " + height);
            if ((flags & WIDTH) != 0)
                System.out.println("Image width = " + width);
            if ((flags & FRAMEBITS) != 0)
                System.out.println("Another frame finished.");
            if ((flags & SOMEBITS) != 0)
                System.out.println("Image section :" + new Rectangle(x, y, width, height));
            if ((flags & ALLBITS) != 0)
                System.out.println("Image finished!");
            if ((flags & ABORT) != 0)
                System.out.println("Image load aborted...");
            return true;
        }/*from  w ww  .  j a  v  a2 s. c om*/
    };

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image img = toolkit.getImage(args[0]);
    toolkit.prepareImage(img, -1, -1, myObserver);
}

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;/*  w  ww. ja  va  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);

    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  www.j a  v  a2  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);

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

From source file:SystemTrayDemo.java

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  a2s.c  om*/
    }

    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

License:asdf

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

    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:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.core.Settings.java

/**
 * Returns the MOEA Framework icons of various sizes.
 * /*from  w ww .  j a va 2 s  .  c  o  m*/
 * @return the MOEA Framework icons
 */
public static List<Image> getIconImages() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    List<Image> icons = new ArrayList<Image>();

    icons.add(toolkit.getImage(Settings.class.getResource("logo16.png")));
    icons.add(toolkit.getImage(Settings.class.getResource("logo24.png")));
    icons.add(toolkit.getImage(Settings.class.getResource("logo32.png")));
    icons.add(toolkit.getImage(Settings.class.getResource("logo48.png")));
    icons.add(toolkit.getImage(Settings.class.getResource("logo64.png")));
    icons.add(toolkit.getImage(Settings.class.getResource("logo128.png")));
    icons.add(toolkit.getImage(Settings.class.getResource("logo256.png")));

    return icons;
}

From source file:MainClass.java

public void load() throws MalformedURLException {
    URL url = new URL("image address");
    Toolkit t = Toolkit.getDefaultToolkit();
    Image im = t.getImage(url);

    MediaTracker mt = new MediaTracker(this);
    mt.addImage(im, 0);/*from   ww w.  ja va2 s.co m*/
    try {
        mt.waitForID(0);
    } catch (InterruptedException e) {
        System.err.println("Unexpected interrupt in waitForID!");
        return;
    }
    if (mt.isErrorID(0)) {
        System.err.println("Couldn't load image file " + url);
        return;
    }
}