java画图中运用缓冲解决屏幕闪烁方案二
2010-11-24 16:24
295 查看
import javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class BufferDrawExample extends MIDlet{ private Display display; private MyCanvas canvas; public BufferDrawExample() { //获取MIDlet的Display对象实例 display = Display.getDisplay(this); //声明Canvas屏幕对象 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 Image image; //声明作为缓冲区的可变图像对象 private Image buffer; private BufferDrawExample bufferDrawExample; public MyCanvas (BufferDrawExample bufferDrawExample) { this.bufferDrawExample = bufferDrawExample; exit = new Command("Exit", Command.EXIT, 1); addCommand(exit); setCommandListener(this); try { //获得图像文件 image = Image.createImage("/12.png"); } catch (Exception e) { System.out.println(e); } //创建可变图像 buffer=Image.createImage(getWidth(),getHeight()); //获取缓冲区的Graphics对象 Graphics graphics=buffer.getGraphics(); //设置颜色 graphics.setColor(255,255,255); //填充屏幕 graphics.fillRect(0, 0, getWidth(), getHeight()); //向缓冲区内绘制图像 graphics.drawImage(image,getWidth()/2,getHeight()/2,graphics.HCENTER|graphics.VCENTER); //释放缓冲区的Graphics对象 graphics=null; } protected void paint(Graphics g) { //将缓冲区的内容绘制到屏幕上 g.drawImage(buffer,getWidth()/2,getHeight()/2,g.HCENTER|g.VCENTER); } public void commandAction(Command command, Displayable displayable) { if (command == exit) { bufferDrawExample.exitMIDlet(); } } }
本文出自 “技术人生” 博客,请务必保留此出处http://zhaohaiyang.blog.51cto.com/2056753/431496
本文出自 “技术人生” 博客,请务必保留此出处http://zhaohaiyang.blog.51cto.com/2056753/431496
相关文章推荐
- java画图中运用缓冲解决屏幕闪烁方案一
- Java Gui中解决游戏闪烁的初级方案(双缓冲技术)
- Windows GDI画图闪烁解决方法 双缓冲技术
- delphi 缓冲画图(内存画图)解决画图闪烁问题
- 双缓冲方法解决屏幕刷新闪烁的问题
- 画图时屏幕闪烁的原因和解决方法
- delphi 缓冲画图(内存画图)解决画图闪烁问题
- wxWidgets学习 - 双缓冲技术解决屏幕闪烁问题
- java双缓冲解决屏幕闪烁
- 双缓冲技术解决屏幕刷新闪烁
- 双缓冲方法解决屏幕刷新闪烁的问题
- delphi 缓冲画图(内存画图)解决画图闪烁问题
- 解决Java设计游戏的时候,画面不动和闪烁问题,双缓冲
- delphi 缓冲画图(内存画图)解决画图闪烁问题
- delphi 缓冲画图(内存画图)解决画图闪烁问题
- 解决java中GUI的闪烁问题
- Java中用双缓冲技术消除闪烁
- 【Unity开发】Unity2D多分辨率屏幕适配方案(IOS露出天空盒解决办法)
- 解决VMware虚拟机中 windows 7 的屏幕闪烁问题
- 使用Image类show图,解决loading过重, 屏幕闪烁问题