ImageCanvas.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:1k
源码类别:
J2ME
开发平台:
Java
- package doublebufferdemo;
- import javax.microedition.lcdui.*;
- import javax.microedition.midlet.*;
- import java.io.*;
- public class ImageCanvas extends Canvas
- {
- private Image buffer;
- private Image image;
- public ImageCanvas()
- {
- try{
- image = Image.createImage("/tree.png");
- }catch(java.io.IOException e){
- System.out.println(e.getMessage());
- }
- buffer = Image.createImage(this.getWidth(), this.getHeight());
- Graphics bg = buffer.getGraphics();
- bg.setColor(0xFFFFFF);
- bg.fillRect(0, 0, getWidth(), getHeight());
- bg.drawImage(image,this.getWidth()/2, this.getHeight()/2, Graphics.VCENTER|Graphics.HCENTER);
- }
- public void paint(Graphics g)
- {
- g.drawImage(buffer,0,0,g.TOP|g.LEFT);
- }
- }