Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

While Loops with paint/repaint

843806Nov 8 2007 — edited Nov 11 2007
ive got a program that needs to loop until either of it's provided integers equal 0, once one does it returns a boolean showing which one(true mean i is 0, false means x is 0) my issue is i need to display this information on a canvas but when a while loop is running it seems to stop it from animating. Animation works fine without the while loop but i need it to do the math.
time=new Timer(400,paintCaller);
time.start();
while(i>0 && x>0)
{
     i-=2;
     x--;
     try
     {
	Thread.sleep(1000);
     }catch(Exception e){}

     if(i<=0)
     {
          return true;
     }else
     {
          return false;
      }
}
the issue with this one is that when the while loop runs it for some reason stops my timer from calling PaintCaller.

while(i>0 && x>0)
{
     repaint();
     i-=2;
     x--;
     try
     {
	Thread.sleep(1000);
     }catch(Exception e){}

     if(i<=0)
     {
          return true;
     }else
     {
          return false;
      }
}
for some reason here, repaint never gets called. (These are 2 seperate codes that i have tried neither work)

I think the while loop messes with the paint method somehow. can anybody help i really want to finish my game, this is the last thing i have to do for it XD
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 9 2007
Added on Nov 8 2007
27 comments
561 views