当前位置: 代码迷 >> J2ME >> 多个canvas切换时,屏幕显示有关问题
  详细解决方案

多个canvas切换时,屏幕显示有关问题

热度:3908   发布时间:2013-02-25 21:38:24.0
多个canvas切换时,屏幕显示问题
写了类似这样的结构:
{
Java code
public class myj2me extends MIDlet {         Display display.....//初始化过程略去         //构造函数中    canvas1 can1 = new canvas1(this);    canvas2 can1 = new canvas2(this);         public void startApp(){display.setCurrent(can1);}         public void setcanvas1(){display.setCurrent(can1);}         public void setcanvas2(){display.setCurrent(can2);}}class canvas1 extends Canvas implements CommandListener {    myj2me j2me;    public canvas1(myj2me my_j2me) {        j2me = my_j2me;    }    public void commandAction(Command cmd,Displayable dis){            if(cmd==...){                     j2me.setcanvas2();            }        }}class canvas2 extends Canvas implements CommandListener {    myj2me j2me;    public canvas2(myj2me my_j2me) {        j2me = my_j2me;    }    public void commandAction(Command cmd,Displayable dis){            if(cmd==...){                     j2me.setcanvas3();            }        }}


初学j2me,想当然的就这样写了,果然有问题,若先显示can1,从can1通过调用setcanvans2()切换到can2的时候屏幕不会刷新,也就是can1的界面还在。

请教一下要如何才能刷新屏幕呢?

------解决方案--------------------------------------------------------
是你的Canvas2的对象错了:

canvas1 can1 = new canvas1(this);
canvas2 can1 = new canvas2(this); ----------------这一行

修改为:
canvas1 can1 = new canvas1(this);
canvas2 can2 = new canvas2(this);

 就可以了