Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Repainting inside loop that uses sleep method

 
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 ]
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your paint method is being invoked recursively
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic