473,513 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delaying a loop

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
Aug 2 '08 #1
7 8960
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();
Aug 2 '08 #2
On 2008-08-02 15:39 Jon Bettinger wrote:
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

--
It ain't THAT, babe! - A radical reinterpretation
http://www.geocities.com/itaintme_babe/itaintme.html
Aug 2 '08 #3
Eustace wrote:
On 2008-08-02 15:39 Jon Bettinger wrote:
>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.
Aug 4 '08 #4
On 2008-08-03 20:39 Jon Bettinger wrote:
Eustace wrote:
>On 2008-08-02 15:39 Jon Bettinger wrote:
>>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
Aug 4 '08 #5
In comp.lang.java message <g7**********@aioe.org>, Mon, 4 Aug 2008
11:17:45, Eustace <em*@email.composted:

Sig:
>Date Calculator with all-purpose JS code
http://www.geocities.com/emfril/js/datecalc.html
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.
Aug 4 '08 #6
On 2008-08-04 14:35 Dr J R Stockton wrote:
In comp.lang.java message <g7**********@aioe.org>, Mon, 4 Aug 2008
11:17:45, Eustace <em*@email.composted:

Sig:
>Date Calculator with all-purpose JS code
http://www.geocities.com/emfril/js/datecalc.html

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
Aug 5 '08 #7
Eustace wrote:
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);
}
}
Aug 5 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2915
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
0
277
by: Fiona McBride | last post by:
Hi all, I have a really odd problem with some Visual Basic .NET 2003 code; I have a program that creates a number of windows which contain RichTextBox, Timers (disabled) and menus. The code...
21
18651
by: Alo Sarv | last post by:
Hi From what I have understood from various posts in this newsgroup, writing event loops pretty much comes down to this: while (true) { handleEvents(); sleep(1); // or _sleep() or...
20
1370
by: pembeci | last post by:
I am using JavaScript to modify some text parts of a loaded document. The functions are loaded from a file at the header and run by: <body onLoad="..."> According to the the Venkman profile...
5
7287
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
3
930
by: Krakatioison | last post by:
I am running a loop which I need to pause for 3 seconds, at the end of each cycle. I found somewhere to use threads.delay(), but I am not using any threads and when I typed it in, it wasn't...
32
2556
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
70
3452
by: hstagni | last post by:
When i read a key using getchar() inside a loop, the program stops and wait for a key to be pressed. I actually want the program to continue its execution until a key is pressed. Look at this...
2
19292
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
0
7259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7158
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7380
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.