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

Paint

 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some text appear in the top left corner of the applet and I wanted to have it move slowly from the top left corner to the bottom right corner.
What way can I get this to happen without causing the applet to blink or cause the client machine to chug? Thanks.

Rob
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to create a thread which, in a loop:

1) Sleeps;
2) Updates the coordinates at which the text should appear;
3) calls repaint().

In your paint() method, paint the new text, at the new coordinates, into an Image object; then copy the Image object onto the screen. This is called "double buffering" and it's what you do to avoid flicker. Here is an article about doing this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic