第1楼 2007-12-09 12:30 starry198804265811 写道:
我的图片怎么加载不到applet中?
我的代码如下:
import java.awt.Color;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.Graphics;
import java.applet.Applet;
import java.net.MalformedURLException;
import java.net.URL;
public class Test2 extends Applet implements ImageObserver {
Image img;
String documentPath;
String codePath;
URL imgURL;
public void init() {
documentPath = getDocumentBase().toString();
codePath = getCodeBase().toString();
try {
imgURL = new URL(getCodeBase(),"test.jpg");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
img = getImage(imgURL);
}
public void paint(Graphics g) {
if (img!=null) {
g.drawImage(img, 0, 0, 600, 300, Color.RED, this );
}
else
g.drawString("图象加载失败!", 10, 150);
g.drawString("documentPath:"+documentPath,10,330);
g.drawString("codePath:"+codePath, 10, 350);
}
}
我的图片没有画上去,程序也没有输出异常信息,"图象加载失败!"并没有被画上去,只有documentPath和codePath画了上去,我本是想加载图象,请问这是怎么回事?