Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Flickering

 
Sharada Kumaran
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an applet which draws strings in a scrolling fashion, and draws images. How can I minimise flickering?
To display the moving text , I use Thread.sleep(). After each sleep interval, I draw the line[x] at (position-1), so that each line is moving up the applet.
Can changing the sleep interval, or the position (ie. make it position - 2), eliminate flickering, or is there a better way of doing this? I can't use update(), because each time the screen must be painted fresh, or the text would overlap.
Would appreciate a speedy response.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Override the update method to the following:



This should stop the flickering, but it may leave "artifacts" of what you were painting on the screen. You have to use double-buffering to overcome this problem. To find out how to use double-buffering, do a search in either this forum or the AWT/JFC/Swing forum for the word "double-buffering" or the words "double" and "buffering". I am sure you will find many posts on this topic that will show you exactly what to do.

-Nate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic