java - trying to make object of class and then to display.setCurrent(Class) but not working -
i trying make new object startgame
, show in gamemidlet
class, whenever click on ok button display content of startgame
, screen doesn't show anything, instead showing same gamemidlet
menu. please me find bug is. thank in advance.
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){ // having problem @ 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) { } }
Comments
Post a Comment