0

我有一个程序,它有一副牌,洗牌,然后随机获得 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>
4

1 回答 1

0

首先,您的 applet 类具有我认为应该具有Cards1的 HTML 代码的名称。DeckofCards1.classCards1.class

此外,似乎存在DeckofCards1.class的目录中还有其他一些小程序类文件,Cards1.class它必须是一个空白小程序。

于 2013-01-18T10:47:33.207 回答