1 Reply Latest reply on May 30, 2014 11:07 AM by mKorbel

    Different behavior after mouse click.

    15874016-df30-4d19-a277-ae450ee6bab3

      When this code executes in line, it correctly displays the first picture for x seconds, then the second picture.

      When this code executes as the result of a mouse click, it incorrectly displays no picture for x seconds, then displays only the second picture. What can I do to get it to display correctly after a mouse click?

       

      JFrame picFrame  = new JFrame   ( "Pictures" );

      ImageIcon myImage1  = new ImageIcon("picture1.png");
      ImageIcon myImage2  = new ImageIcon("picture2.png");

      FlowLayout  myFlow = new FlowLayout();

      JLabel  picLabel1 = new JLabel(myImage1);
      JLabel  picLabel2 = new JLabel(myImage2);

      int loopCount = 100000;

      picFrame.setSize   ( 200, 400 );
      picFrame.setLayout ( myFlow );
      picFrame.setVisible (true);

      picFrame.add (picLabel1);
      picLabel1.setVisible (true);

      //-------------
      // Slow it down
      //-------------     
      for (int i = 1  ;  i < loopCount; i = i + 1)
      {
          for (int j = 1  ;  j < loopCount; j = j + 1)
           {
               Math.sqrt (i);
           }
      }

      picLabel1.setVisible (false);

      picFrame.add (picLabel2);
      picLabel2.setVisible (true);