• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Repainting inside loop that uses sleep method

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your paint method is being invoked recursively
 
reply
    Bookmark Topic Watch Topic
  • New Topic