title: Change ImageIcon in JLabel using Timer
body: <p>I have two classes: logic and the <code>JFrame</code>. In frame I have a <code>JLabel</code> and a <code>JButton</code>, and I would like to:</p>
  
  <p>When this button is clicked, the <code>ImageIcon</code> in the label changes after a determined time using a Swing <code>Timer</code>, like if it is flashing. To do it I loaded two images with different brightness (<code>img1b</code> and <code>img1</code>). I tried to make the timer change the image twice with different delays, but I was unsuccessful. I also put a listener in the button and implemented the <code>actionPerformed</code> as below:</p>
  
  <pre><code>public void actionPerformed(ActionEvent e) {
      if(e.getSource().equals(btnImg1)) {
          logic.piscaImagen(img1, lblImg1);
          logic.piscaImagen(img1b, lblImg1);
  </code></pre>
  
  <p>In logic class:</p>
  
  <pre><code>public void piscaImagen(ImageIcon img, JLabel lbl) {
  
          Timer timer = new Timer(1250, null);
          timer.addActionListener(new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent evt){
                  if(lbl.getIcon() != img){
                      lbl.setIcon(img);
              }
          }
          });
          timer.setRepeats(false);
          timer.start();
  }
  </code></pre>
  
  <p>But when I run it nothing changes in the <code>logic.piscaImagen</code>. Any tips?</p>