You really don't need to. Just be sure that you are doing expensive calculations and such outside of the paint() method and only painting the results. Paint will be called any time the OS needs to update the screen (ie moving, resizing, etc) so try to keep it as lean as possible. If you want to play with buffered image painting, that is one way to keep a copy of what you have already drawn and then draw over it as needed, but for your small example I don't think you need to do that.
You may also want to consider overriding paintComponent() of your JPanel instead of paint(), since paint also paints the borders and child components. paintComponent() is more narrowed to the area you are wanting to render.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Offline 6,761 posts
since May 2007