J2me 从一个页面跳转到另一个Canvas界面

在Eclipse中做一个这样的界面:第一页显示一个选项“查看”然后点击转到另外一个Canvas页面该页面的独立运行代码如下:importjavax.microeditio... 在Eclipse中做一个这样的界面:第一页显示一个选项“查看” 然后点击转到另外一个Canvas页面 该页面的独立运行代码如下:
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class DrawString extends MIDlet {
private Display display;

private StringCanvas sc;

//被绘制的字符串
private final static String STR = "Hello";

public DrawString() {
super();
sc = new StringCanvas();
}

protected void startApp() throws MIDletStateChangeException {
//获得当前MIDlet的Display对象
display = Display.getDisplay(this);
//设置StringCanvas对象为当前显示对象
display.setCurrent(sc);
}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void destroyApp(boolean arg0)
throws MIDletStateChangeException {
// TODO Auto-generated method stub

}

class StringCanvas extends Canvas {

protected void paint(Graphics g) {
g.setColor(123,205,134);

g.drawString(STR, 0, 0,
Graphics.LEFT | Graphics.TOP);
g.drawString(STR, 108, 145,
Graphics.LEFT | Graphics.TOP);
g.drawString(STR, 208, 275,
Graphics.LEFT | Graphics.TOP);

}
}

}
展开
 我来答
kira0001
2008-04-13 · 超过36用户采纳过TA的回答
知道小有建树答主
回答量:85
采纳率:0%
帮助的人:88.7万
展开全部
paint前没有用白色填充画面,所以运行的时候字符串都画在菜单上了,看起来很怪

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;

public class DrawString extends MIDlet {
private Display display;

private StringCanvas sc;

private MenuList menu;

//被绘制的字符串
private final static String STR = "Hello";

public DrawString() {
super();
sc = new StringCanvas();
menu = new MenuList(this);
}

protected void startApp() throws MIDletStateChangeException {
//获得当前MIDlet的Display对象
display = Display.getDisplay(this);
//设置StringCanvas对象为当前显示对象
display.setCurrent(menu);
}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub

}

protected void menuDrawString(){
//获得当前MIDlet的Display对象
display = Display.getDisplay(this);
//设置StringCanvas对象为当前显示对象
display.setCurrent(sc);
}

protected void menuListQuit(){

}

class StringCanvas extends Canvas {

protected void paint(Graphics g) {
g.setColor(123,205,134);

g.drawString(STR, 0, 0,
Graphics.LEFT | Graphics.TOP);
g.drawString(STR, 108, 145,
Graphics.LEFT | Graphics.TOP);
g.drawString(STR, 208, 275,
Graphics.LEFT | Graphics.TOP);

}
}

class MenuList extends List implements CommandListener{
private DrawString midlet;
private Command exitCommand;

MenuList(DrawString midlet){//退出
super("Kira0001", List.IMPLICIT);
this.midlet = midlet;

append("查看", null);

exitCommand = new Command("退出", Command.EXIT, 1);
addCommand(exitCommand);

setCommandListener(this);
}

public void commandAction(Command c, Displayable d){
if (c == List.SELECT_COMMAND){
int index = getSelectedIndex();
if (index != -1){ // should never be -1
if (index == 0){
midlet.menuDrawString();
}
}
}
else if (c == exitCommand){
midlet.menuListQuit();
}
}
}

}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式