本文介绍了J2ME.游戏画布形式切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个游戏画布和一个表单.我使用display.setCurrent[<gamecanvas>]</gamecanvas>将控件切换到GameCanvas,如何从GameCanvas切换到Form?无法使用display.setCurrent?请帮帮我.

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.

推荐答案

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.


这篇关于J2ME.游戏画布形式切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 13:55