Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // VolatileImageRenderer.java
- // SwingEasel
- //
- // Created by Philip Rhodes on 8/20/05.
- // Copyright 2005 Philip J Rhodes. All rights reserved.
- //
- import java.awt.*;
- import java.awt.image.*;
- /** This abstract class provides a VolatileImage for double buffering. Although
- * Swing provides double buffering by default, using a VolatileImage allows
- * the Java Virtual Machine (JVM) to take advantage of hardware acceleration.
- * Even if a particular JVM doesn't do this, or if there is no 3D graphics card
- * installed, there may still be an advantage to using an image, because each
- * drawing operation may be slightly faster.
- */
- public abstract class VolatileImageRenderer extends ImageRenderer{
- /** Create a VolatileImageRenderer to render the shapes in the World w.*/
- VolatileImageRenderer(World w, int width, int height, boolean showFPS){
- super(w, width, height, showFPS);
- }
- /** Creates the Volatile image and associated Graphics object. The image
- * takes its dimensions from the size of the JPanel. (Remember that this
- * class is a child of JPanel. IMPORTANT NOTE: The JPanel must be visible
- * when this method is called. So, call setVisible(true) BEFORE calling
- * init(). Even if you do this, there may be a race condition if your JVM
- * uses a separate thread to schedule repaints. Because of this, the init()
- * method will loop until it succeeds in creating a volatile image.
- */
- public void init(){
- do {
- this.backingImage = createVolatileImage(this.imageWidth, this.imageHeight);
- } while(this.backingImage == null);
- this.imageGraphics = this.backingImage.getGraphics();
- }
- public void render(){
- if(this.imageGraphics == null){
- this.init();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement