Search Results

Search found 1 results on 1 pages for 'terranova993'.

Page 1/1 | 1 

  • strange bug - how to pause a java program?

    - by TerraNova993
    I'm trying to: display a text in a jLabel, wait for two seconds, then write a new text in the jLabel this should be simple, but I get a strange bug: the first text is never written, the application just waits for 2 seconds and then displays the final text. here is the example code: private void testButtonActionPerformed(java.awt.event.ActionEvent evt) { displayLabel.setText("Clicked!"); // first method with System timer /* long t0= System.currentTimeMillis(); long t1= System.currentTimeMillis(); do{ t1 = System.currentTimeMillis(); } while ((t1 - t0) < (2000)); */ // second method with thread.sleep() try { Thread.currentThread().sleep(2000); } catch (InterruptedException e) {} displayLabel.setText("STOP"); } with this code, the text "Clicked!" is never displayed. I just get a 2 seconds - pause and then the "STOP" text. I tried to use System timer with a loop, or Thread.sleep(), but both methods give the same result.

    Read the article

1