I am drawing an animation onto a swing JPanel. The 1024x1024 screen is divided up into 2000 pieces which cover the screen exactly (no overlap).
each piece is a very small piece of the screen (1/2000'th of it). The animation draws one piece every millisecond by changing the pixels in the buffered image and calling reaint(). So at the entire screen changes every 2 seconds. The animation is run in a java.util.Timer task.
The buffered image is not accelerated and is not volatile. I set it's priority to 1.
The frame root pane is optimized. Both the front and back buffer are accelerated but not volatile.
This works ok.
Profiling indicates that almost all of the grahics time is spend drawing the buffered image as one would expect, Using some dirty rectangles does not seem to help reduce the paint time.
If I clip the drawing of the buffered image with it's exact shape, that piece gets painted and the rest of the screen turns white.
What I want to is to have the rest of the screen stay the way it was and just have the clipped shape get painted.
Making the pixels for each piece requires blending 10 layers, so there is some computation done there.
could/should this be done better in an awt timer thread?
Or should i use a canvas and the update trick http://java.sun.com/products/jfc/tsc/articles/painting/src/UpdateDemo.java
I have seen suggestion that include Toolkit.getDefaultToolkit().setDynamicLayout(true); System.setProperty("sun.awt.noerasebackground","true");
other suggestions include paintimmedialtely, and subclassing JComponent instead of JPanel.
I find this all somewhat confusing.
I would like to keep this OS independent as much as possible, but the app will run mostly on windows 7.
What is the next (small) logical step for me to take here?
Update: Using a canvas (without the update trick) remarkably reduced the time spent drawing the buffered image. Instead of this being on the top line of the profiler, i can't find it! i may be doing more than i should when i use the panel.
See Question&Answers more detail:
os