黑莓 ButtonField 应用程序示例

标签 blackberry buttonfield changelistener

我对黑莓应用程序非常陌生。

现在尝试使用 eclipse 在黑莓中创建计算器:

所以我添加了一个按钮(ButtonField),我的第一个目标是当按下这个按钮时我想要显示

嗨..现在您可以尝试使用文本字段。

这里是我的代码,请看一下。

Launcher.java

public class Launcher extends UiApplication {
    public static void main(String[] args) {
        Launcher theApp = new Launcher();
        theApp.enterEventDispatcher();
   }
   private Launcher()
   {
       this.pushScreen(new MainScrn());
   }

}

MainScrn.java

public class MainScrn extends MainScreen implements FieldChangeListener {
    public MainScrn() {
        LabelField lf_hello = new LabelField();
        lf_hello.setText("Hello, World!");
        lf_hello.setBackground(BackgroundFactory.createSolidBackground(124));
        ButtonField mySubmitButton = new ButtonField("clickMe");
        mySubmitButton.setChangeListener(this);
        this.add(lf_hello);
        this.add(mySubmitButton);
    }

    public void fieldChanged(Field field, int context) {
        System.out.println("hi.. now you can try with text field");

    }
}

你好,这有什么问题吗? ?请帮忙.. 这对你来说很简单,但对我来说不是吗?

最佳答案

在字段更改监听器中,替换此代码

 public void fieldChanged(Field field, int context) {
        System.out.println("hi.. now you can try with text field");
 }

public void fieldChanged(Field field, int context) {
    if(field == mySubmitButton) {
        System.out.println("hi.. now you can try with text field");
    }      
}

不要只写你想做的事情。首先检查它是否是 ButtonField 然后为其编写代码。

关于黑莓 ButtonField 应用程序示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8164137/

相关文章:

java - Blackberry Java 可以做参数化类型吗?

blackberry - 在黑莓项目中创建的文件类型

c# - 如果 ButtonFields 文本不被视为 TableCell,我如何访问它?

java - 这似乎用红色下划线

java - BufferedImage 的 Changellistener

java - 更改 RCP 应用程序中的项目性质

java - Blackberry 中的 invokeLater 内部的线程

blackberry - 在支持加速度计的黑莓设备上拍照后透视图像错误

Asp.Net Gridview Buttonfield获取行数据

c# - 从 templatefields gridview 获取值 - C#