title: Button's icon not appear when click on it
body: <p>I am making a memory icons game in a very simple way. I have a problem when I clicked on the second button the icon of that but not appear but the code can do everything else correct, i think the problem is in the actionPerformed method where i deal with the clicked buttons:</p>
  
  <pre><code>package ButtonsGsme;
  
  import javax.swing.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.concurrent.TimeUnit;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  public class Buttons extends JFrame implements ActionListener{
      JButton lastPressed = null;
      int buttonsPressed = 0;
      Cards c = new Cards();
       Icon[] iconPaths = {new ImageIcon(getClass().getResource("tiger.png")),
                       new ImageIcon(getClass().getResource("tiger.png")),
                       new ImageIcon(getClass().getResource("chicken.png")),
                       new ImageIcon(getClass().getResource("chicken.png"))};
      ArrayList&lt;Icon&gt; icons = new ArrayList &lt;&gt;();
      JButton buttonsArr[] = new JButton[4];
  
      public Buttons(){
          setLayout(null);
          for(int i = 0; i &lt; 4; i++) {
              buttonsArr[i] = new JButton();
          }
          for(int i = 0; i &lt; 4; i++) {
              icons.add(iconPaths[i]);
          }
          Collections.shuffle(icons);
  
          buttonsArr[0].setBounds(100, 100, 200, 140);
          buttonsArr[1].setBounds(350, 100, 200, 140);
          buttonsArr[2].setBounds(100, 300, 200, 140);
          buttonsArr[3].setBounds(350, 300, 200, 140);
  
          for (int i = 0; i &lt; 4; i++) {
              add(buttonsArr[i]);
              buttonsArr[i].addActionListener(this);
          }
      }
      // To give each button its icon
      public void pressedIcon(JButton b) {
          for (int i = 0; i &lt; 4; i++){
              if(b == buttonsArr[i]) {
                  buttonsArr[i].setIcon(icons.get(i));
              }
          }
      }
  
      public boolean matched(JButton b1, JButton b2){
          if (b1.getIcon().toString().equals(b2.getIcon().toString())) {
              return true;
          }
          else {
              return false;
          }
      }
  
      @Override
      public void actionPerformed(ActionEvent e) {
          buttonsPressed++;
          pressedIcon((JButton) e.getSource());
          if (buttonsPressed == 2) {
              try {
                  // To stop a second with two buttons' icons show face up
                  TimeUnit.SECONDS.sleep(1);
              } 
              catch (InterruptedException ex) {
                  Logger.getLogger(Buttons.class.getName()).log(Level.SEVERE, null, ex);
              }
              if (matched(lastPressed, (JButton) e.getSource()) == false) {
                  lastPressed.setIcon(null);
                  ((JButton) e.getSource()).setIcon(null);
              }
              buttonsPressed = 0;
          }
          else {
              lastPressed = (JButton) e.getSource();
          }
      }
  } 
  </code></pre>
  
  <p>This is what happen when i click on the second button (the bottom left) it holds like that for a second (the timer that i set) then nothing appear </p>
  
  <p><a href="https://i.stack.imgur.com/56Ygk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/56Ygk.png" alt="This is what happen when i click on the second button (the bottom left) it holds like that for a second (the timer that i set) then nothing appear "></a></p>