被我注释的地方会出现异常,高手指点下!!!!!
import java.awt.TextField;
import java.applet.Applet;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.net.URL;
public class HelloApplet extends Applet{
Image bird=null;
Image bird1=null;
URL url1=null;
URL url2=null;
public void init(){
System.out.println(getCodeBase());
System.out.println(getDocumentBase());
try{
url1=new URL("file:/G:/JavaApplication1/b.jpg");
url2=new URL("file:/G:/JavaApplication1/");
}catch(Exception e){
System.out.println("异常");
}
System.out.println("URL:"+url1.toString());
//bird=Toolkit.getDefaultToolkit().getImage(url1);//异常
//bird=Toolkit.getDefaultToolkit().getImage("b.jpg");//异常
//bird1=this.getImage(url1);//异常
//bird1=this.getImage(url2,"b.jpg");//异常
bird1=this.getImage(this.getCodeBase(),"bird.jpg");
//bird1=this.getImage(this.getDocumentBase(),"bird.jpg");//异常
}
public void paint(Graphics g){
g.drawImage(bird,200,150,90,90,this);
g.drawImage(bird1,20,50,80,80,this);
}
}
求助关于getImage()的问题