我正在尝试从StartGame
创建一个新对象,并在GameMidlet
类中显示,但每当我点击 OK 按钮显示StartGame
的内容时1}},屏幕不显示任何内容,而是显示相同的GameMidlet
菜单。请帮我找一下bug的位置。先感谢您。
public class GameMidlet extends MIDlet implements CommandListener, ItemCommandListener {
GameCanvas gameCanvasNew;
Display display;
StartGame startGame;
Command restartCommand;
Vector mGameCanvasList;
GameCanvas gameCanvasSecond;
private Form formMenu;
private Command exitCommand;
private Command okCommand;
private Command exitCommandGame;
private StringItem menuItem;
private StringItem siNewGameItem;
private StringItem siResume;
private StringItem siExit;
public void startApp() {
formMenu = new Form("Start Menu", new Item[] {getNewGameItem(), getResumeItem(), getExitItem()});
display = Display.getDisplay(this);
display.setCurrent(formMenu);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
}
public StringItem getNewGameItem(){
if(siNewGameItem == null){
siNewGameItem = new StringItem("New Game","", Item.BUTTON);
siNewGameItem.addCommand(getOkCommand());
siNewGameItem.setItemCommandListener(this);
}
return siNewGameItem;
}
public StringItem getResumeItem(){
if(siResume == null){
siResume = new StringItem("Resume", "", Item.BUTTON);
siResume.addCommand(getOkCommand());
siResume.setItemCommandListener(this);
}
return siResume;
}
public StringItem getExitItem(){
if(siExit == null){
siExit = new StringItem("Exit","",Item.BUTTON);
siExit.addCommand(getExitCommand());
siExit.setItemCommandListener(this);
}
return siExit;
}
public Command getOkCommand(){
if(okCommand == null){
okCommand = new Command("OK", Command.OK, 0);
}
return okCommand;
}
public Command getExitCommand(){
if(exitCommand == null){
exitCommand = new Command("Exit", Command.EXIT, 0);
}
return exitCommand;
}
public void commandAction(Command c, Item item) {
if(item == siExit){
if(c == exitCommand){
destroyApp(true);
notifyDestroyed();
}
}
else if(item == siNewGameItem){
if(c == okCommand){
// i am having problem at here......
startGame = new StartGame();
display.setCurrent(startGame);
startGame.startGameNew();
}
}
}
}
StartGame.java
public class StartGame extends Canvas implements CommandListener {
GameCanvas game;
Display display;
Command exitCommand;
Command restartCommand;
Vector mGameCanvasList;
GameCanvas fistList;
public void startGameNew() {
game = new GameCanvas();
exitCommand = new Command("Exit", Command.EXIT, 0);
restartCommand = new Command("Restart", Command.OK, 0);
game.addCommand(exitCommand);
game.addCommand(restartCommand);
game.setCommandListener(this);
game.setCommandListener(this);
game.startThread();
}
protected void paint(Graphics g) {
}
}