Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Repainting inside loop that uses sleep method  RSS feed

 
Flo Powers
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this may not be the right section for this post - may be an issue more suited under the swing section, for example - not sure...

I'm making a simple application that draws shapes on a JFrame (not with applet, but with a class that extends JFrame and has a main method). The paint method runs an endless while loop in which I invoke Thread.sleep(3000) in a try-catch block.

The try block also creates a Polygon with 3 - 8 points (all within the bounds of the window), and paints it with reference to the Graphics object. I then try to invoke repaint for each loop. I have experienced before that I've got that to work with applets, but not with an "application" (by which I mean it has a main method, and doesn't require an appletviewer or a web page in which to run).

It also doesn't unload the process from RAM when I click the close button on the window, even though in the main method I've added a WindowListener. Could that be because of the while loop with the Thread? I.e. it's not listening when I click, because the Thread is sleeping...?

I don't know what's wrong, other than (probably) my overall approach... Any comments? Here's the code so far:



[ March 27, 2006: Message edited by: Flo Powers ]
[ March 27, 2006: Message edited by: Flo Powers ]
 
Harish Kashyap
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your paint method is being invoked recursively
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!