我正在编写一个小程序,它将随机挑选 10 张卡片并在屏幕上显示它们。但是,我收到一个 .class 错误和一个 ; 当我尝试传递字符串 [] 时需要错误。有人帮忙吗?这是我的代码:
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Image;
import java.applet.Applet;
import java.lang.Math;
import java.util.Random;
public class unit12Assignment extends Applet
{
Image card1 ... card52;
public void init()
{
card1 = getImage( getDocumentBase(), "c1.gif" );
...
card52 = getImage( getDocumentBase(), "sk.gif" );
}
public void getCards()
{
String cardNumber;
double cardRandom;
int cardRandomNumber;
String[] cardSelection = new String[10];
Random ran = new Random();
for (int number = 0; number <= 9; )
{
cardRandom = ran.nextInt(52) + 1;
cardRandomNumber = (int) Math.round( cardRandom );
if ( cardRandomNumber > 0 && cardRandomNumber <= 52 )
{
cardNumber = "card" + cardRandomNumber;
number++;
}
}
paint( String[] cardSelection );
}
public void paint(Graphics g, String[] card)
{
setBackground( Color.green );
g.drawImage( card[0], 10, 10, this);
g.drawImage( card[1], 90, 10, this);
g.drawImage( card[2], 170, 10, this);
g.drawImage( card[3], 250, 10, this);
}
}