animatedcanvas.java.svn-base
来自「example2 众多JAVA实例源码...学习java基础的好帮手」· SVN-BASE 代码 · 共 45 行
SVN-BASE
45 行
package opusmicro.demos.animate;
import java.util.*;
import javax.microedition.lcdui.*;
// A canvas to which you can attach one or more
// animated images. When the canvas is painted,
// it cycles through the animated images and asks
// them to paint their current image.
public class AnimatedCanvas extends Canvas {;
private Display display;
private Image offscreen;
private Vector images = new Vector();
public AnimatedCanvas( Display display ){
this.display = display;
// If the canvas is not double buffered by the
// system, do it ourselves...
if( !isDoubleBuffered() ){
offscreen = Image.createImage( getWidth(), getHeight() );
}
}
// Add an animated image to the list.
public void add( AnimatedImage image ){
images.addElement( image );
}
// Paint the canvas by erasing the screen and then
// painting each animated image in turn. Double
// buffering is used to reduce flicker.
protected void paint( Graphics g ){
Graphics saved = g;
if( offscreen != null ){
g = offscreen.getGraphics();
}
g.setColor( 255, 255, 255 );
g.fillRect( 0, 0, getWidth(), getHeight() );
int n = images.size();
for( int i = 0; i < n; ++i ){
AnimatedImage img = (AnimatedImage)images.elementAt( i );
img.draw( g );
}
if( g != saved ){
saved.drawImage( offscreen, 0, 0, Graphics.LEFT | Graphics.TOP );
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?