j2me两个canvas如何切换,就如一个UI一个result的canvas
j2me主程序中的startApp中显示了UI的canvas;我能不能在UI中的操作:例如按一个按钮弹出result那个Canvas来,如何做?另外,会不会canvas中...
j2me主程序中的startApp中显示了UI的canvas;我能不能在UI中的操作:例如按一个按钮弹出result那个Canvas来,如何做?
另外,会不会canvas中调用textbox来输入的做法。
我很菜,会的话,告诉一下我。谢谢先! 展开
另外,会不会canvas中调用textbox来输入的做法。
我很菜,会的话,告诉一下我。谢谢先! 展开
2个回答
展开全部
下面的呢看一下吧
是我做的一个示例
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class GameTest extends MIDlet {
private Display display;
private Canvas canvas1;
private Canvas canvas2;
private Command command;
public GameTest() {
display = Display.getDisplay(this);
}
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
canvas1 = new Canvas1("First Canvas");
canvas2 = new Canvas1("Second Canvas");
display.setCurrent(canvas1);
}
private class Canvas1 extends Canvas {
String msg;
public Canvas1(String msg) {
command = new Command("Next Canvas",Command.SCREEN,1);
this.msg = msg;
this.addCommand(command);
this.setCommandListener(new CommandListenerImp());
}
protected void paint(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(255,0,0);
g.drawString(msg,30,30,0);
}
}
private class CommandListenerImp implements CommandListener {
public void commandAction(Command c, Displayable d) {
display.setCurrent(canvas2);
}
}
}
是我做的一个示例
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class GameTest extends MIDlet {
private Display display;
private Canvas canvas1;
private Canvas canvas2;
private Command command;
public GameTest() {
display = Display.getDisplay(this);
}
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
canvas1 = new Canvas1("First Canvas");
canvas2 = new Canvas1("Second Canvas");
display.setCurrent(canvas1);
}
private class Canvas1 extends Canvas {
String msg;
public Canvas1(String msg) {
command = new Command("Next Canvas",Command.SCREEN,1);
this.msg = msg;
this.addCommand(command);
this.setCommandListener(new CommandListenerImp());
}
protected void paint(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(255,0,0);
g.drawString(msg,30,30,0);
}
}
private class CommandListenerImp implements CommandListener {
public void commandAction(Command c, Displayable d) {
display.setCurrent(canvas2);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询