这个小程序假设显示两张图片彼此重叠。当我在浏览器中运行这个小程序时,它不显示图片。图片名称是正确的,它们与小程序位于同一文件夹中。
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
public class question3b extends JApplet{
public void init() {
repaint();
}
public void paint(Graphics g)
{
super.paint(g);
ImageIcon image1 = new ImageIcon("1.JPG");
ImageIcon image2 = new ImageIcon("2.JPG");
g.drawImage(image1.getImage(), 100, 20 , 100, 100, this);
g.drawImage(image2.getImage(), 100, 150 , 100, 100, this);
}
}
这是 HTML 页面。
<html>
<head>
<title>Welcome Java Applet</title>
</head>
<body>
<applet
code = "question3b.class"
width = 1000
height = 500>
</applet>
</body>
</html>