有两点问题:
1.img为空。
2.没有绘制这个图像。
img = getImage(imgURL, imgPath);
if(img ==null){//判断是不是为空
System.out.println("Image is null!");
}else{//不为空则显示图像
g.drawImage(img,xpoint,ypoint,img.getWidth(this),img.getHeight(this),this);
}
}
1.img为空。
2.没有绘制这个图像。
img = getImage(imgURL, imgPath);
if(img ==null){//判断是不是为空
System.out.println("Image is null!");
}else{//不为空则显示图像
g.drawImage(img,xpoint,ypoint,img.getWidth(this),img.getHeight(this),this);
}
}
我的html是这样写的:
<html>
<head>
<title>"MyApplet text"
</title>
<body>
<applet code="MyApplet.class" width=500 height=500 /applet>
</body>
</head>
</html>
try {
URL url = new URL(getDocumentBase()+imgPath);
} catch (MalformedURLException e) {
textField1.setText(e.toString());
}
import java.applet.*;
import java.awt.image.*;
import java.awt.image.ImageObserver;
import java.net.URL; public class MyApplet extends Applet implements ImageObserver{
Image img;
String imgPath = "";
int xpoint = 100, ypoint = 100; public void init() { setBackground(Color.white); //设置背景色
setForeground(Color.blue); //设置前景色
Container cp = getContentPane();
cp.add(new JLabel("test.jpg"));}
不就可以了,为什么要用paint