Java 2D Graphics If you’d rather not use
Java 2D Graphics If you’d rather not use this feature, you can disable it with a call to the following method in the JComponent class: public void setDoubleBuffered(boolean aFlag) This method determines whether double buffering will be used for this component or not. If aFlag is true, then drawing will be performed in an offscreen buffer belonging to either this component or one of its visual parents. If aFlag is false, this component’s drawing will be performed directly on the screen. 14.4 Optimizations Performance tuning is a complex subject I’ve really only scratched the surface in this chapter. The example programs show the relative “cost” of different kinds of operations, but there are several techniques you can use to optimize your applications. Two of these techniques are listed below: prerendering For some applications it makes sense to render transformed shapes, images, or text into offscreen buffers. These can be selectively transferred to the screen during an animation. In many cases, this technique is significantly faster than doing the rendering in real time. It’s a trade-off you buy speed by using more memory. smart update The examples in this chapter erase the offscreen buffer and render the whole thing at every time step. In some applications, it’s possible to redraw just a portion of the entire onscreen component. For example, this technique would be helpful in animating a small character over a large background. Other optimization techniques exist, but they are out of the scope of this book. This chapter gives you the tools you need to examine the cost of different operations in the 2D API.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services