我有一个带有一副牌的程序,将牌组洗牌,然后获得10张随机牌,并将它们分别显示为两行,每行五张。我编译了程序,并编译了html页面,但是当我运行html页面时,appletviewer是空白的......为什么会这样?
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
public class Cards1 extends Applet{
Image[] image = new Image[52];
public void init() {
image[0] = getImage(getDocumentBase( ),"images/c1.gif");
image[1] = getImage(getDocumentBase( ),"images/c2.gif");
// ...
image[48] = getImage(getDocumentBase( ), "images/h10.gif");
image[49] = getImage(getDocumentBase( ), "images/hj.gif");
image[50] = getImage(getDocumentBase( ), "images/hq.gif");
image[51] = getImage(getDocumentBase( ), "images/hk.gif");
}
public void paint(Graphics g) {
//Shuffle
for (int i = 0; i < image.length; i++) {
int index = (int)(Math.random() * image.length);
Image temp = image[i];
image[i] = image[index];
image[index] = temp;
}
//Display first row
int index = 0;
for(int j = 0; j < 294; j += 71) {
g.drawImage(image[index++], 10 + j, 10, this);
}
//Display second row
index = 5;
for(int j = 0; j < 294; j += 71) {
g.drawImage(image[index++], 10 + j, 106, this);
}
}
}
// html代码
<html>
<head>
<title>DisplayCards</title>
</head>
<body>
<applet code = "DeckofCards1.class" width = 8000 height = 8000> </applet>
</body>
</html>
答案 0 :(得分:0)
首先,applet类的名称为Cards1
,而HTML代码为DeckofCards1.class
,我觉得应该是Cards1.class
。
此外,似乎在DeckofCards1.class
存在的目录中还有一些其他applet类文件Cards1.class
,它必须是一个空白小程序。