java画图中运用缓冲解决屏幕闪烁方案一
来源:技术人生 责任编辑:admin 发表时间:2013-07-01 19:04 点击:次
	   
	import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MutableImageExample extends MIDlet
{
  private Display  display;     
  private MyCanvas canvas;   
  public MutableImageExample ()
  {
    display = Display.getDisplay(this);
    canvas  = new MyCanvas (this);
  }
  protected void startApp()
  {
    display.setCurrent( canvas );
  }
  protected void pauseApp()
  { 
  }
  protected void destroyApp( boolean unconditional )
  { 
  }
  public void exitMIDlet()
  {
    destroyApp(true);
    notifyDestroyed();
  }
  class MyCanvas extends Canvas implements CommandListener
  {
    private Command exit;  
    private MutableImageExample mutableImageExample;
    private Image image = null;
    public MyCanvas(MutableImageExample mutableImageExample)
    {
      this. mutableImageExample = mutableImageExample;
      exit = new Command("Exit", Command.EXIT, 1);
      addCommand(exit);
      setCommandListener(this);
      try
      {
		 //声明一个可变图像,并初始化这个图像
        image = Image.createImage(70, 70);
		//获得访问可变图像的Graphics对象
        Graphics graphics = image.getGraphics();
		//设置画笔颜色
        graphics.setColor(255, 0, 0);
		//在可变图像中填充圆弧
        graphics.fillArc(10, 10, 60, 50, 180, 180);  
      }
      catch (Exception error)
      {
		 //显示创建可变图像错误信息
        Alert alert = new Alert("绘制失败","创建不变图像", null, null);
        alert.setTimeout(Alert.FOREVER);
        display.setCurrent(alert);
      }    
    } 
    protected void paint(Graphics graphics)
    {
      if (image != null)
      {
		//清屏操作
       graphics.setColor(255,255,255);
       graphics.fillRect(0, 0, getWidth(), getHeight());
	   //绘制可变图像
       graphics.drawImage(image, 30, 30, 
                    Graphics.VCENTER | Graphics.HCENTER);
      }
    }
    public void commandAction(Command command, Displayable display)
    {
相关新闻>>
- 发表评论
 - 
				
 
- 最新评论 进入详细评论页>>
 






