I am working on matching a game with photos, I think I can reset imageIcon to find out the name conteiner lable, and then reset the tag icon when ismatch returns false in the isMatch method.
write the following code on each label, reset only work on the second label. What should I do?
public ImageIcon firstChoice; public ImageIcon SecoundChoice; public boolean isSelected = false; public boolean isMatch = true; public boolean ismatch(ImageIcon firstChoice, ImageIcon secoundChoce) { if (firstChoice.getImage() == secoundChoce.getImage()) { JOptionPane.showMessageDialog(null, " wowo you got it ^^"); isMatch = true; } else { JOptionPane.showMessageDialog(null, " notmatced"); isMatch = false; } return isMatch; } // label Mouse Clicked private void label1MouseClicked(java.awt.event.MouseEvent evt) { label1.setIcon(new ImageIcon("G:/Games/icons/File Server Asia.png")); if (isSelected == true) { ImageIcon icon1 = (ImageIcon) label1.getIcon(); firstChoice = icon1; if (SecoundChoice != null && firstChoice != null) { } boolean match = ismatch(firstChoice, SecoundChoice); if (isMatch == false) { label1.setIcon(null); firstChoice = SecoundChoice = null; } } else { if (SecoundChoice == null) { ImageIcon icon1 = (ImageIcon) label1.getIcon(); SecoundChoice = icon1; isSelected = true; } if (isMatch == false) { label1.setIcon(null); } } }
source share