代号一个带按钮的打开应用程序

codename one open app with a button

我对如何使用按钮感到困惑。我打开主题设计器并创建按钮,然后在命令上我选择执行操作并转到源代码(之前保存)

在代码上我有这个方法,在模拟器上什么也不做,在设备上也不做(在模拟器上启动一个打开文件 window,我使用的是 w7)

 @Override
protected boolean onMainCommand105() {

    try {
        Display.getInstance().execute("fb://profile/14846274855890");
    } catch (Exception e) {
        Dialog.show("Error!", "Failed to start.  installed?", "OK", null);
        e.printStackTrace();
    }
    return true;
}

这是正确的方法吗?

感谢这个 CN1 教程,我看到了我的错误

http://www.codenameone.com/how-do-i---handle-eventsnavigation-in-the-gui-builder--populate-the-form-from-code.html

我应该使用动作事件,而不是执行

@Override
protected void onMain_Button1Action(Component c, ActionEvent event) {
     try {
        Display.getInstance().execute("https://www.facebook.com/CatedralAltaPatagonia/?fref=ts");
    } catch (Exception e) {
        Dialog.show("Error!", "Failed to start.  installed?", "OK", null);
        e.printStackTrace();
    }

}

或更简单:

button.addActionListener(l -> {

    System.out.println("test");          

});