title: The background color changes after the for loop exits. Can anyone explain?
body: <p>CellPane is a JPanel. In constructor i have added a mouse listener.When clicked the background should change to blue and then print on console the values. But the problem is first the values are printed and then the background changes. Why?</p>
  
  <pre><code>public CellPane() {
              addMouseListener(new MouseAdapter() {
                  @Override
                  public void mouseClicked(MouseEvent e) {
                      defaultBackground = getBackground();
                      setBackground(Color.BLUE);
                      for(int i=0;i&lt;1000000;i++)
                      {
                          System.out.println(i);
                      }
                  }
  
                  @Override
                  public void mouseExited(MouseEvent e) {
                      setBackground(defaultBackground);
                  }
              });
          }
  </code></pre>