import java.awt.Image; import java.net.*; import java.io.*;import javax.imageio.ImageIO;
public class Downloader extends Thread{ String urlStr; int index; Image[] imgs;
public Downloader(String urlStr, Image[] imgs, int index){ this.imgs = imgs; this.urlStr = urlStr; this.index = index;
}public void run(){ try{ URL url = new URL(urlStr); URLConnection urlc = url.openConnection(); imgs[index] = ImageIO.read(urlc.getInputStream()); } catch (IOException ie){ ie.printStackTrace(); } }
public static void main(String[] args){ Image[] imgs = new Image[1]; new Downloader("http://funini.com/trip/imgs/denmark.jpg", imgs, 0).run(); System.out.println("Width = " + imgs[0].getWidth(null)); } }