gpt4 book ai didi

java - 图像图标列表

转载 作者:行者123 更新时间:2023-12-01 15:56:57 26 4
gpt4 key购买 nike

可以使用像

这样的列表
    private LinkedList<Object> deckOfCards = new LinkedList<Object>();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 13; j++) {
deckOfCards.add(new Card(Rank.values()[j].toString(), Suit.values()[i].toString(), number[j], Image[j]));
}
}
}

当我这样做时

public Object pickRandomCard() {
Random randomNumbers = new Random();
rand = randomNumbers.nextInt(deckOfCards.size());
System.out.println(deckOfCards.get(rand).toString());
return deckOfCards.get(rand).toString();
}


//***********************

public void setImage(ImageIcon Image) {
this.cardImage = Image;
}

public ImageIcon getImage() {
return deckOfCards.get(rand).getImage();
}

我收到LinkedList 类型的 getImage() 方法未定义

目前我可以返回卡的名称,但不能返回图像,我该怎么做?

构造函数

打包游戏;

导入javax.swing.ImageIcon;

公共(public)课卡{ 私有(private)字符串面; 私有(private)绳索套装; 私有(private)整数; 私有(private) ImageIcon 图像;

Card(String faceCard, String faceSuit, int value, ImageIcon ImageO) {
face = faceCard;
suit = faceSuit;
number = value;
Image = ImageO;
}


public String toString() {
return face + " of " + suit;
}


public ImageIcon getImage() {
return Image;
}


public int toInt() {
return number;
}


public String suit(){
return suit;
}

}

最佳答案

使用Card而不是Object:

private LinkedList<Card> deckOfCards = new LinkedList<Card>();
...
public Card pickRandomCard() {
...

关于java - 图像图标列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4881813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com