Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Sleep not working in loop
    primarykey
    data
    text
    <p>What I want to do in my java program is, that when I press the button it displays text in <code>textfield</code> in intervals of time. i.e I press the button then a <code>jFrame</code> pops up and there is a label which shows text like: 1st second:"1st" then a time lag of say 1 sec then 2nd thing: "2nd"</p> <p>I am a newbie and I tried to Google this problem but I couldn't find a solution even after 3-4 hours I tried a lot of things: sleep, try n catch...</p> <p>Please write the answer very simplified.</p> <p>Here is my code: In the following code, when the button is pressed, the jFrame comes but has a white screen in it and when the sum ends, its screen turns grey and it shows the answer....</p> <pre><code> private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { See.setVisible(true);//See is the JFrame t007.setVisible(true);//Label in See l2.setVisible(true);//TextField in See int ran, g, d, col, ran2; double y = 1000 * (Double.parseDouble(t2.getText())); int x = (int) y; d = 0; double c = Math.pow(10, Integer.parseInt(t1.getText())); col = Integer.parseInt(t3.getText()); for (g = 0; g &lt; col;) { ran = (int) (Math.random() * (c)); // Random Number Creation Starts if (ran &gt; (c / 10)) { g = g + 1; ran2 = ((int) (Math.random() * 10)) % 2; if (ran2 == 1) { ran = ran * (-1); } d = d + ran; if (d &lt; 0) { ran = ran * (-1); d = d + (2 * ran); } l2.setVisible(true); t007.setText("" + ran); System.out.println("" + ran); jButton6.doClick(); //Pausing (Sleep) try { Thread.sleep(x); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } } l2.setText("" + d); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload