多张图片的载入

import java.awt.*;
import java.net.MalformedURLException;
import java.net.URL;

import com.sun.jndi.toolkit.url.Uri;
public class WriteImage extends Frame{
Image[] im;
Toolkit tk;
URL[] ur;
public WriteImage(String title) throws Exception{
super(title);
setVisible(true);
setSize(800,900);
tk=this.getToolkit();
ur=new URL[2];
im=new Image[2];
ur[0]=new URL("http://www.haotuku.com/katong/touwenzid/010j.jpg");
ur[1]=new URL("http://t2.baidu.com/it/u=2170347506,696194363&gp=41.jpg");
im[0]=tk.getImage(ur[0]);
im[1]=tk.getImage(ur[1]);
MediaTracker mt=new MediaTracker(this);
mt.addImage(im[0],1);
mt.addImage(im[1],2);
System.out.println("图像加载中");
mt.waitForAll();
if(mt.isErrorAny()){
System.out.println("加载出错");
System.exit(1);
}

}

public void paint(Graphics g){
g.drawImage(im[0],80,50,this);
g.drawImage(im[1],30,80,this);
System.out.println("图像加载完毕");
}
public static void main(String[] args) throws Exception {
Frame f=new WriteImage("daoru");

}

}

你可能感兴趣的:(图片)