Toolkit: getImage(URL url) : Toolkit « java.awt « Java by API






Toolkit: getImage(URL url)

 
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JPanel;

public class MainClass extends JPanel {

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

    MediaTracker mt = new MediaTracker(this);
    mt.addImage(im, 0);
    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;
    }
  }

  public static void main(String[] args) {

  }
}


           
         
  








Related examples in the same category

1.Toolkit: addAWTEventListener(AWTEventListener listener, long eventMask)
2.Toolkit: createImage(byte[] img)
3.Toolkit: beep()
4.Toolkit: getColorModel()
5.Toolkit: getDefaultToolkit()
6.Toolkit: getMenuShortcutKeyMask()
7.Toolkit: getProperty(String key, String def)
8.Toolkit: getScreenResolution()
9.Toolkit: getScreenSize()
10.Toolkit: getSystemClipboard()
11.Toolkit: getSystemEventQueue()
12.Toolkit: prepareImage(Image image, int width, int height, ImageObserver observer)