我有这种方法:
我正在尝试将卡片的图片分配到他们的iconCards[][]
个人资料中。图片位于图像/文件夹中,例如images/AS.gif (Ace of Spades), images/AD.gif (Ace of Diamonds)
等。
static void loadCardIcons(){
int l =0;
int k =0;
while (k < 14){
for (l = 0; l < 4; l++){
String card = "images/" + Character.toString(valueRanks[k]) + "C.gif";
iconCards[k][l] = new ImageIcon(card);
System.out.println(k + " " + l + " " + card);
card = "images/" + Character.toString(valueRanks[k]) + "D.gif";
iconCards[k][l++] = new ImageIcon(card);
System.out.println(k + " " + l + " " + card);
card = "images/" + Character.toString(valueRanks[k]) + "H.gif";
iconCards[k][l++] = new ImageIcon(card);
System.out.println(k + " " + l + " " + card);
card = "images/" + Character.toString(valueRanks[k]) + "S.gif";
iconCards[k][l++] = new ImageIcon(card);
System.out.println(k + " " + l + " " + card);
k++;
}
}
iconBack = new ImageIcon("images/BK.gif");
}
...12 3 images/KS.gif
13 0 images/XC.gif
13 1 images/XD.gif
13 2 images/XH.gif
13 3 images/XS.gif
*13
2
images/XS.gif*
你可以看到value = 13 and suit = 2
。根据上面的输出卡应该是images/XH (JokerHearts)
,但它打印我 XS。为什么?这是运行它的方法。无法找出发生了几周的事情。
static public Icon getIcon(Card card){
loadCardIcons();
return iconCards[valueAsInt(card)][suitAsInt(card)];
}