473,570 Members | 2,882 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(10 00);
} catch(Interrupt edException 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 reinterpretatio n
http://www.geocities.com/itaintme_babe/itaintme.html
Aug 2 '08 #1
7 8963
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(10 00);
} catch(Interrupt edException 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.flus h();
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)calculat es 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(10 00);
} catch(Interrupt edException 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
instantaneousl y 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.flus h();
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 reinterpretatio n
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)calculate s 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(10 00);
} catch(Interrupt edException 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.flu sh();

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)calculat es 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(10 00);
} catch(Interrupt edException 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.fl ush();

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**********@a ioe.org>, Mon, 4 Aug 2008
11:17:45, Eustace <em*@email.comp osted:

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.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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**********@a ioe.org>, Mon, 4 Aug 2008
11:17:45, Eustace <em*@email.comp osted:

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 reinterpretatio n
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(thi s);
}
}
Aug 5 '08 #8

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

Similar topics

0
2925
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 G23_NA17192.fsa rs7374540 A/C I23_Control.fsa rs7374540 C/C
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 runs fine and creates the windows as required, BUT if the program is left to do nothing for several hours, when it is brought back into focus it...
21
18682
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 nanosleep(), depending on platform }
20
1381
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 the scripts run in a total of 170 milliseconds. However, when I load the page I can see the original form of the document (original text) and I can...
5
7290
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; int digit3 = 0; for( ; digit1 < 5 ; digit1++ ) {
3
934
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 even recognized as a command. So what I am doing now is this: for a = 0 to 15000 dim d as integer = a*a
32
2571
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 memories are of but I think I just said loop somewhere inside the loop and it immediately jumped back to the start of the loop and began again. I can't...
70
3467
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 sample: ------ while(1=1) { printf("oi"); ch=getchar(); if (ch=='q') break; }
2
19297
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 iterates a specified number of times, requires you to also implement or decrement some sort of Loop Counter, while a For...Next Loop does that work for you....
0
7633
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8149
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7699
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6323
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5523
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3671
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2131
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 we have to send another system
1
1238
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
971
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.