如何在J2ME移动应用程序中的画布上显示对话框?

时间:2011-12-29 05:15:45

标签: java java-me lwuit lcdui

  

可能重复:
  Is this possible to use lwuit.Dialog with javax.microedition.lcdui.Canvas in wireless toolkit 2.5.2?

当我按下移动键时,我创建了一个写入内容的画布(例如,如果我按下“A”,它将使用绘画功能写在屏幕上)。现在,当我从移动设备按任意键时,我想显示一个对话框或PopUp窗口。是否可以在使用Canvas时显示对话框?

说一些例子,

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

     }

2 个答案:

答案 0 :(得分:1)

好的,我认为你必须这样做。 LWUIT中正确的做法是使用Dialog

使用Dialog创建new。即Dialog d = new Dialog()

下一步是使用Dialog.setTitle(String text)填充标题和正文,或在Dialog的布局中添加内容。

当您Dialog已准备好展示时,您必须致电Dialog.show(),如果要将其删除,请致电Dialog.dispose()

看看这里

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

答案 1 :(得分:0)

如果是出于调试目的,您可以使用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

警报适用于表格和画布。