j2me中如何实现多个Canvas之间的切换,知道的帮帮忙
如题,下面一段代码是一个简单的Canvas界面,如何再加个Canvas界面,通过按右软键(键值是-7),切换到下面这个Canvas界面?麻烦高手说下在哪里加代码impor...
如题,下面一段代码是一个简单的Canvas界面,如何再加个Canvas界面,通过按右软键(键值是-7),切换到下面这个Canvas界面?麻烦高手说下在哪里加代码
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class Midlet extends MIDlet
{Display display;
Canvas canvas;
public Midlet()
{display=Display.getDisplay(this);
canvas=new KeyCanvas();}
public void startApp()
{display.setCurrent(canvas);
canvas.setFullScreenMode(true);}
public…pause…
public…destroy…
}
public class keyCanvas extends Canvas
{
public keyCanvas(){}
protected void paint(Graphics g)
{g.setColor(0,0,100);
g.fillRect(0,0,240,320);
g.setColor(100,0,0);
g.drawString("切换",220,300,Graphics.LEFT|Graphics.BASELINE);}
protected void keyPressed(int key){}
protected void keyReleased(int key){}
protected void keyRepeated(int key){}
}
找到方法了 tengge的教程里有,在按键事件里加个条件语句,重画图,在画图方法也加个条件语句 展开
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class Midlet extends MIDlet
{Display display;
Canvas canvas;
public Midlet()
{display=Display.getDisplay(this);
canvas=new KeyCanvas();}
public void startApp()
{display.setCurrent(canvas);
canvas.setFullScreenMode(true);}
public…pause…
public…destroy…
}
public class keyCanvas extends Canvas
{
public keyCanvas(){}
protected void paint(Graphics g)
{g.setColor(0,0,100);
g.fillRect(0,0,240,320);
g.setColor(100,0,0);
g.drawString("切换",220,300,Graphics.LEFT|Graphics.BASELINE);}
protected void keyPressed(int key){}
protected void keyReleased(int key){}
protected void keyRepeated(int key){}
}
找到方法了 tengge的教程里有,在按键事件里加个条件语句,重画图,在画图方法也加个条件语句 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询