This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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
Sheriff
Posts: 24215
37
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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!