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

Redrawing images causes flickering on-screen  RSS feed

 
Reyver Cris Laureto
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm currently doing my system now and i have i little problem i hope somebody can help. ^_^ my problem is about inserting an image to my jframe form with thread because if i insert image
and when i run it it blinks too slow comparing if i use simple oval it doesnt blink. help plss.

why is it that if i wrote the code like this.



my application is blinking i think its because im using image because if i do like this the simple way.



my application is smooth. im currently improving my design. anybody who can help me?

by the way here the way heres how i declare my thread



 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to calculate the sleep time between frames of the animation of the thread to achieve an acceptable frame rate. Your Thread.sleep(100); call is not accurate to achieve 10 frames per second because you loose a random amount of time between paints. You have to track the time and sleep exactly the number of miilis needed.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't want to override the paint() method directly, because you lose the default double-buffering behaviour that Swing provides for all lightweight components. You should override the paintComponent() method instead. Look at this page for some helpful guidelines for painting in Swing. Also, make sure you do all your painting on the Event Dispatch Thread (EDT), more on that here.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!