开发者

Can I use canvas and form together in a application

Can I use Canvas and form tog开发者_运维百科ether in application? If yes then how can I access form from Canvas?


Yes you can use both but not at the same time. You can switch between them by using Display.setCurrent().


You need your Midlet to find its display (and the form).You would to send a reference of your MIDlet to the canvas constructor.So your canvas would be look like this:

class myCanvas extends Canvas implements ... {
myMIDlet myHost; // the breadcrumb

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

    ...
}   

Where "myMIDlet" is name of your MIDlet.
In your MIDlet:

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

When you want to got to the form from "myCanvas" (probably in a commandAction or keyPressed methods of your canvas) do this:

Display disp = myHost.getDisplay();
disp.setCurrent(myHost.myForm);

Reference:
codeproject


You can switch form to canvas. For example:

        canvasName c=new canvasName(this);
        Display.getDisplay(this).setCurrent(c);

But, in Canvas to Form, I don't know.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜