我正在制作一个“记忆卡游戏”,并试图检查两个图标是否匹配,如何比较图标? (它们在jLabels上设置)。 我目前只在使用if(lbl1.getIcon()== lbl8.getIcon())
lbl1.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
lbl1.setIcon(new
ImageIcon(getClass().getResource("/pictures/teo.png")));
i++;
if(i == 2)
{
i = 0;
if(lbl1.getIcon() == lbl8.getIcon())
{
System.out.println("match");
}
}
}
});