Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a game canvas and a form. I switch control to the GameCanvas using display.setCurrent[<gamecanvas>]</gamecanvas> how do i switch from GameCanvas to Form ? unable to use display.setCurrent? Please help me out.
Posted
Updated 22-Sep-11 6:19am
v2

1 solution

You need to leave some breadcrumbs to find your way back to your Midlet to find its display (and the form). Something along these lines:

Java
public class myMIDlet extends MIDlet implements ... {
...
Form myForm = new Form( ... 
...
myGameCanvas ggg = new myGameCanvas(... , this) // <=== note the last parameter - the key to it all
...
display.setCurrent(ggg);
...
}

class myGameCanvas extends GameCanvas implements ... {
myMIDlet myHost; // the breadcrumb

    public myGameCanvas(... , myMIDlet host) {
    super(...);
    myHost = host; // remember our host MIDlet
    ...
    }

    ... wherever you want to got to the form (probably in a commandAction or keyPressed)
    Display disp = myHost.getDisplay();
    disp.setCurrent(myHost.myForm);

}


Cheers,
Peter
If this answers your question, mark it as accepted. Vote anyway.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900