Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Paint  RSS feed

 
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: 24217
38
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!