Delaying a loop 
August 2nd, 2008, 01:05 PM
| | |
I have a program that contains a do-while loop, inside of which it
(re)calculates a array of labels XY[x][y], each one consisting of a
single digit, and print them forming an x by y rectangle. What I want to
do is slow the loop down so I can see the different formations of the
digits; so I tried
try {
Thread.sleep(1000);
} catch(InterruptedException ex) {}
at the end of the loop, expecting to see the number formations changing
every second, like seeing a film frame by frame. Instead, however, there
was a loooooong delay, and then the loop reached almost instantaneously
its conclusion.
How can I stop the execution of the loop until I have time to see the
results in each pass?
Eustace
--
It ain't THAT, babe! - A radical reinterpretation http://www.geocities.com/itaintme_babe/itaintme.html | 
August 2nd, 2008, 08:45 PM
| | | | re: Delaying a loop
Eustace wrote: Quote:
I have a program that contains a do-while loop, inside of which it
(re)calculates a array of labels XY[x][y], each one consisting of a
single digit, and print them forming an x by y rectangle. What I want to
do is slow the loop down so I can see the different formations of the
digits; so I tried
>
try {
Thread.sleep(1000);
} catch(InterruptedException ex) {}
>
at the end of the loop, expecting to see the number formations changing
every second, like seeing a film frame by frame. Instead, however, there
was a loooooong delay, and then the loop reached almost instantaneously
its conclusion.
>
How can I stop the execution of the loop until I have time to see the
results in each pass?
>
Eustace
>
| Try flushing the io before the call to sleep. Your output is probably
being buffered.
i.e., if using System.out,
System.out.flush(); | 
August 2nd, 2008, 09:35 PM
| | | | re: Delaying a loop
On 2008-08-02 15:39 Jon Bettinger wrote: Quote:
Eustace wrote: Quote:
>I have a program that contains a do-while loop, inside of which it
>(re)calculates a array of labels XY[x][y], each one consisting of a
>single digit, and print them forming an x by y rectangle. What I want
>to do is slow the loop down so I can see the different formations of
>the digits; so I tried
>>
>try {
> Thread.sleep(1000);
>} catch(InterruptedException ex) {}
>>
>at the end of the loop, expecting to see the number formations
>changing every second, like seeing a film frame by frame. Instead,
>however, there was a loooooong delay, and then the loop reached almost
>instantaneously its conclusion.
>>
>How can I stop the execution of the loop until I have time to see the
>results in each pass?
>>
>Eustace
>>
| >
Try flushing the io before the call to sleep. Your output is probably
being buffered.
i.e., if using System.out,
System.out.flush();
| Thanks. That makes sense. But I am not using System.out, the program
extends JFrame and I am using the setText command to change the JLabels
that have been added to the JPanel of the Container. How do I flush in
this case?
Eustace
--
It ain't THAT, babe! - A radical reinterpretation http://www.geocities.com/itaintme_babe/itaintme.html | 
August 4th, 2008, 01:45 AM
| | | | re: Delaying a loop
Eustace wrote: Quote:
On 2008-08-02 15:39 Jon Bettinger wrote: Quote:
>Eustace wrote: Quote:
>>I have a program that contains a do-while loop, inside of which it
>>(re)calculates a array of labels XY[x][y], each one consisting of a
>>single digit, and print them forming an x by y rectangle. What I want
>>to do is slow the loop down so I can see the different formations of
>>the digits; so I tried
>>>
>>try {
>> Thread.sleep(1000);
>>} catch(InterruptedException ex) {}
>>>
>>at the end of the loop, expecting to see the number formations
>>changing every second, like seeing a film frame by frame. Instead,
>>however, there was a loooooong delay, and then the loop reached
>>almost instantaneously its conclusion.
>>>
>>How can I stop the execution of the loop until I have time to see the
>>results in each pass?
>>>
>>Eustace
>>>
| >>
>Try flushing the io before the call to sleep. Your output is probably
>being buffered.
>i.e., if using System.out,
>System.out.flush();
| >
Thanks. That makes sense. But I am not using System.out, the program
extends JFrame and I am using the setText command to change the JLabels
that have been added to the JPanel of the Container. How do I flush in
this case?
>
Eustace
>
| Hmmm, I'm not a swing expert, but you could try calling invalidate on
the component that changed. | 
August 4th, 2008, 04:25 PM
| | | | re: Delaying a loop
On 2008-08-03 20:39 Jon Bettinger wrote: Quote:
Eustace wrote: Quote:
>On 2008-08-02 15:39 Jon Bettinger wrote: Quote:
>>Eustace wrote:
>>>I have a program that contains a do-while loop, inside of which it
>>>(re)calculates a array of labels XY[x][y], each one consisting of a
>>>single digit, and print them forming an x by y rectangle. What I
>>>want to do is slow the loop down so I can see the different
>>>formations of the digits; so I tried
>>>>
>>>try {
>>> Thread.sleep(1000);
>>>} catch(InterruptedException ex) {}
>>>>
>>>at the end of the loop, expecting to see the number formations
>>>changing every second, like seeing a film frame by frame. Instead,
>>>however, there was a loooooong delay, and then the loop reached
>>>almost instantaneously its conclusion.
>>>>
>>>How can I stop the execution of the loop until I have time to see
>>>the results in each pass?
>>>>
>>>Eustace
>>>>
>>>
>>Try flushing the io before the call to sleep. Your output is
>>probably being buffered.
>>i.e., if using System.out,
>>System.out.flush();
| >>
>Thanks. That makes sense. But I am not using System.out, the program
>extends JFrame and I am using the setText command to change the
>JLabels that have been added to the JPanel of the Container. How do I
>flush in this case?
>>
>Eustace
>>
| Hmmm, I'm not a swing expert, but you could try calling invalidate on
the component that changed.
| Thanks anyway. I prefer the newsgroups, but now I'll try the Sun forums.
--
Date Calculator with all-purpose JS code http://www.geocities.com/emfril/js/datecalc.html | 
August 4th, 2008, 11:55 PM
| | | | re: Delaying a loop
In comp.lang.java message <g776g2$kk8$1@aioe.org>, Mon, 4 Aug 2008
11:17:45, Eustace <emf@email.composted:
Sig: Does it handle Ordinal Date, ISO Week Number, Julian/Gregorian, and
Easter Sunday? How about the Hebrew, Islamic, etc., calendars? Without
all of those, and more, it cannot be accurately described as all-
purpose.
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links. | 
August 5th, 2008, 12:45 PM
| | | | re: Delaying a loop
On 2008-08-04 14:35 Dr J R Stockton wrote: Quote:
In comp.lang.java message <g776g2$kk8$1@aioe.org>, Mon, 4 Aug 2008
11:17:45, Eustace <emf@email.composted:
>
Sig:>
Does it handle Ordinal Date, ISO Week Number, Julian/Gregorian, and
Easter Sunday? How about the Hebrew, Islamic, etc., calendars? Without
all of those, and more, it cannot be accurately described as all-
purpose.
| Dear Dr. Stockton.
We have crossed paths again. I most certainly do not intend to compete
with your unrivaled JavaScript subroutines. But mine have been useful
for some who still program in outdated languages (the owner of a QBasic
website was most thankful for sending him my subroutines, another
programmer once thanked me for helping him get a job - before 2000), and
I still prefer them as simpler when location, daylight savings time,
other calendars, and other considerations would unnecessarily complicate
the calculations.
One might argue, though, that the description "all-purpose JS code" is
not the best I could choose. I just intended it to mean that it is for
general, common, purposes and not for special ones - an all-purpose
product is not expected to be the best in any particular case, but than
your methods are an exception to that rule, being both "all-purpose" and
thorough. "Generic" might have been a better choice in my case, meaning
that it can be used in all computing languages, including those that do
not include a Date function. Anyway, I include occasionally the
signature with the description hoping to attract the curiosity of
someone who might find them useful for his/her purposes.
I certainly sense a feeling of jealousy, or maybe rather a kind of
competitiveness on your part, and I would like to express my sincere
gratitude for the deep sense of satisfaction that it has provided me. I
may insist that the variable name "epoch" would better apply to a 400
year period, and that the counting would more rationally start with year
1CE rather than 1970CE, but now such questions are of course of purely
academic interest; the alternate options have been established, and we
know very well that when such things get established it is very
difficult to change them. And anyway, personally I would be much more
interested to see the US adopt the metric system in my lifetime than to
have my opinions on the date functions prevail.
Cheers,
Eustace
--
It ain't THAT, babe! - A radical reinterpretation http://www.geocities.com/itaintme_babe/itaintme.html | 
August 5th, 2008, 03:45 PM
| | | | re: Delaying a loop
Eustace wrote: Quote:
On 2008-08-02 15:39 Jon Bettinger wrote:
Thanks. That makes sense. But I am not using System.out, the program
extends JFrame and I am using the setText command to change the JLabels
that have been added to the JPanel of the Container. How do I flush in
this case?
>
Eustace
>
| What you probably want to do is something like this (pseudo code):
public class StuffDoer implements Runnable {
private void recalculate() {
//...
}
private void repaint() {
//...
}
public void run() {
Thread.sleep(30);
recalculate();
repaint();
SwingUtilities.invokeLater(this);
}
} |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|