gpt4 book ai didi

java - 更改对象参数

转载 作者:行者123 更新时间:2023-12-01 18:34:33 25 4
gpt4 key购买 nike

我有这段代码

        for (int j = 0; j < 2; j++) {

// Shuffle images array
Collections.shuffle(Arrays.asList(cards));

for (int i = 0; i < cards.length; i++) {

// Create new instance of card
final Card card = new Card(cards[i].getCardID(), cards[i].getCardImage());

ImageIcon icon = card.getDefIcon();
card.setIcon(icon);
this.add(card);


card.addMouseListener(new MouseAdapter()
{
card.clicked = true;
public void mouseReleased(MouseEvent e)
{


}
});

}

}

但是“card.clicked = true”行有错误标记“clicked”上存在语法错误,该标记后面应有 VariableDeclaratorld

Card 类如下所示

public class Card extends JLabel {
int cardID;
public boolean clicked = false;
BufferedImage cardImage;
ImageIcon defIcon = new ImageIcon("E:/Java Projects/UUR - Semestralka/resources/card.png");


Card (int cardID, BufferedImage cardImage) {
this.cardID = cardID;
this.cardImage = cardImage;
}

public int getCardID() {
return cardID;
}

public BufferedImage getCardImage() {
return cardImage;
}

public ImageIcon getDefIcon() {
return defIcon;
}
}

有人知道我做错了什么吗?

最佳答案

你需要输入

card.clicked = true;

方法内部如下

public void mouseReleased(MouseEvent e) 
{
card.clicked = true;
}

关于java - 更改对象参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22637528/

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