/Users/lyon/j4p/src/graphics/graph/ImageUtil.java

1    package graphics.graph; 
2     
3    import java.awt.*; 
4     
5    public class ImageUtil 
6            /** 
7             *  The responsibility of this class is to aid in the 
8             *  creating of screen images for double buffering. 
9             */ { 
10       private Panel p = new Panel(); 
11       private Image offscreen; 
12       private Dimension offscreensize; 
13       private Graphics offgraphics; 
14    
15       public Graphics getOffGraphics() { 
16           return offgraphics; 
17       } 
18    
19       public Dimension getOffScreenSize() { 
20           return offscreensize; 
21       } 
22    
23       public Image getOffScreen() { 
24           return offscreen; 
25       } 
26    
27       public void setPanel(Panel panel) 
28               /** 
29                *  this will let the ImageUtil perform what it 
30                *   needs to do on a specific desired panel. 
31                */ { 
32           p = panel; 
33       } 
34    
35       public void createBuffer(Dimension d) { 
36           offscreen = p.createImage(d.width, d.height); 
37           offscreensize = d; 
38           if (offgraphics != null) 
39               offgraphics.dispose(); 
40           offgraphics = offscreen.getGraphics(); 
41           offgraphics.setFont(p.getFont()); 
42       } 
43   }