title: Thread sleep inside of actionPerformed method
body: <p>First of all I want to say I'm aware this aproach is wrong so I'm asking this question because of pure curiousity. Lets say I have a swing application like this:</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.ImageIcon;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.SwingUtilities;
  
  public class ThreadSleeping {
      JFrame frame = new JFrame();
      JPanel panel = new JPanel();
      JButton button = new JButton("Load");
      JLabel label = new JLabel();
  
      public ThreadSleeping() {
          panel.add(button);
  
          button.addActionListener(new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent arg0) {
                  label.setIcon(new ImageIcon(
                          "C:/Users/Public/Pictures/Sample Pictures/Tulips.jpg"));
                  System.out.println("Tulips painted");
                  try {
                      Thread.sleep(2000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
                  label.setIcon(new ImageIcon(
                          "C:/Users/Public/Pictures/Sample Pictures/Koala.jpg"));
                  System.out.println("Koala painted");
  
              }
          });
  
          frame.add(panel, BorderLayout.NORTH);
          frame.add(label, BorderLayout.CENTER);
          frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          frame.setSize(1024, 768);
          // frame.pack();
          frame.setVisible(true);
      }
  
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                  new ThreadSleeping();
              }
          });
      }
  }
  </code></pre>
  
  <p>Basically when I click a <code>Load</code> button I expect that <code>Tulips.jpg</code> image displays then GUI freezes for a 2 seconds and after that I expect that <code>Koala.jpg</code> image displays. But what happens is that: I click on button, GUI freezes for a 2 seconds and <code>Koala.jpg</code> displays. No <code>Tulips.jpg</code> before that. But thing that confuses me is when I put those <code>System.out.println("Tulips painted");</code> and <code>System.out.println("Koala painted");</code>. So when I click on button it prints "Tulips painted" and after 2 seconds "Koala painted". Can someone tell me whats going on here? Regards.</p>