How can I show dialog box on canvas in J2ME mobile application? [duplicate]

泄露秘密 提交于 2019-12-13 10:39:25

问题


Possible Duplicate:
Is this possible to use lwuit.Dialog with javax.microedition.lcdui.Canvas in wireless toolkit 2.5.2?

I created a canvas to write contents when I press mobile keys(for Example if I press "A" it will be written on the screen using paint function). Now I want to show a dialog or PopUp window when I press any key from mobile. Is it possible to show dialog when am using Canvas?

say some example,

   public class Mycanvas extends Canvas implement ActionListener
   {
     Dialog dialog=new Dialog();

     }

回答1:


Ok, I think you must do that. The right thing in LWUIT is using Dialog.

Create a Dialog using new. i.e. Dialog d = new Dialog()

The next step is filling the title and body with Dialog.setTitle(String text) or putting something inside the Dialog's layout.

When your Dialog is ready to be shown, you must call to Dialog.show() and when you want to remove it, call to Dialog.dispose()

Take a look here

Is this possible to use lwuit.Dialog with javax.microedition.lcdui.Canvas in wireless toolkit 2.5.2?




回答2:


If it is for debugging purpose you can use Alert instead. Here's an example how you can use Alert:

//you need to import javax.microedition.lcdui;
Alert alert = new Alert("Info", "Here's the key code/string", null, AlertType.INFO);
alert.setTimeout(3000);    // for 3 seconds
display.setCurrent(alert, yourcanvasname);    // so that it goes to back to your canvas after displaying the alert

Alert works fine with both forms and canvases.



来源:https://stackoverflow.com/questions/8664243/how-can-i-show-dialog-box-on-canvas-in-j2me-mobile-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!