ImageCanvas.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:1k
源码类别:

J2ME

开发平台:

Java

  1. package doublebufferdemo;
  2. import javax.microedition.lcdui.*;
  3. import javax.microedition.midlet.*;
  4. import java.io.*;
  5. public class ImageCanvas extends Canvas
  6. {
  7. private Image buffer;
  8. private Image image;
  9. public ImageCanvas()
  10.         {
  11.         try{
  12.         image = Image.createImage("/tree.png"); 
  13.         }catch(java.io.IOException e){
  14.         System.out.println(e.getMessage());
  15.         }
  16.         buffer = Image.createImage(this.getWidth(), this.getHeight());
  17.         Graphics bg = buffer.getGraphics();
  18.         bg.setColor(0xFFFFFF);
  19.         bg.fillRect(0, 0, getWidth(), getHeight());
  20.         bg.drawImage(image,this.getWidth()/2, this.getHeight()/2, Graphics.VCENTER|Graphics.HCENTER);
  21.         }
  22.         public void paint(Graphics g)
  23.         {
  24. g.drawImage(buffer,0,0,g.TOP|g.LEFT);
  25.         }
  26. }