/* アニメーション実験 Ver 0.10 */ /* */ /* */ /* by Atsushi 2005/8/20 */ package animation; import java.awt.*; class AnimationCanvas extends Canvas { /* --- Field --- */ private Animation animation; private Image offscreen; /* --- Constructor --- */ public AnimationCanvas(Animation animation) { this.animation=animation; } /* --- 描画処理 --- */ public void paint(Graphics g) { Dimension size; int x,y; if (offscreen==null) { offscreen=animation.createImage(this); animation.startAnimation(); } size=size(); // getSize() x=size.width /2-offscreen.getWidth (null)/2; y=size.height/2-offscreen.getHeight(null)/2; g.drawImage(offscreen,x,y,null); } public void update(Graphics g) { paint(g); } /* --- Invalidate --- */ public void invalidate() { super.invalidate(); if (offscreen!=null) offscreen.flush(); offscreen=null; } /* --- Finalizer --- */ public void finalize() throws Throwable { if (offscreen!=null) offscreen.flush(); super.finalize(); } }