【发布时间】:2015-04-10 05:33:37
【问题描述】:
我正在尝试为每个卡片对象添加正确的图像,但我似乎无法让它工作。我试图将它合并到我的 fillDeck() 方法中,但不确定最好的方法是什么。
这是我得到的:
public void fillDeck() {
Iterator suitIterator = CardSuit.VALUES.iterator();
while(suitIterator.hasNext()) {
CardSuit suit = (CardSuit) suitIterator.next();
Iterator rankIterator = CardValue.VALUES.iterator();
while(rankIterator.hasNext()) {
CardValue value = (CardValue) rankIterator.next();
/* This is the problem area :L */
String imageFile = imageLocation + Card.getImageFilename(suit, value);
ImageIcon image = new ImageIcon(getImage(getCodeBase(), imageFile));
/* --------------------------- */
Card card = new Card(suit, value, image);
addCard(card);
}}}
图片位置初始化为:private final String imageLocation = "cardImages/";
而getImageFilename如下:
public static String getImageFilename( CardSuit suit, CardValue value ) {
return suit.getSuitAcronym() + value.getValueAcronym() + ".png";
}
我正在检查 imageIO,但不太确定如何将其实现到其中。这也是我的文件树,可能是我将图像文件夹放在错误的位置:http://i.stack.imgur.com/Jt6po.png
所以,是的,很抱歉这篇长文,希望有人能提供一些关于我应该如何处理这个问题的见解,或者你是否能发现一些错误。
【问题讨论】: