Delaying a loop

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eustace

    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
    Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!

  • Jon Bettinger

    #2
    Re: Delaying a loop

    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();

    Comment

    • Eustace

      #3
      Re: Delaying a loop

      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
      Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!

      Comment

      • Jon Bettinger

        #4
        Re: Delaying a loop

        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.

        Comment

        • Eustace

          #5
          Re: Delaying a loop

          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
          Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!

          Comment

          • Dr J R Stockton

            #6
            Re: Delaying a loop

            In comp.lang.java message <g776g2$kk8$1@a ioe.org>, Mon, 4 Aug 2008
            11:17:45, Eustace <emf@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.

            Comment

            • Eustace

              #7
              Re: Delaying a loop

              On 2008-08-04 14:35 Dr J R Stockton wrote:
              In comp.lang.java message <g776g2$kk8$1@a ioe.org>, Mon, 4 Aug 2008
              11:17:45, Eustace <emf@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
              Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!

              Comment

              • Robert Larsen

                #8
                Re: Delaying a loop

                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);
                }
                }

                Comment

                Working...