在 CodenameOne 中创建容器时出现的问题

Problems when creating containers in CodenameOne

对于我的主应用程序,我需要一个用于导航目的的自定义容器,请参阅 (Whosebug)。

由于发布的解决方案对我不起作用(我尝试使用简单的 System.out.println),我开始了一个新项目以了解容器嵌入的工作原理,但它没有按我预期的方式工作。

所以新的应用程序是橙色的 Hi World 应用程序。

我在 GUI 设计器中创建了一个新的空白容器并添加了 3 个按钮。

  1. 我在 GUI 设计器中创建了一个新的空白容器并添加了 3 个按钮。
  2. 我在容器
  3. 中为它们添加了一个actionListener
  4. 我将容器添加到表单中

我的状态机看起来像这样:

@Override
protected void onButtonCont_ButtonAction(Component c, ActionEvent event) {

System.out.println("button1 clicked");
}

@Override
protected void onButtonCont_Button1Action(Component c, ActionEvent event) {

    System.out.println("button2 clicked");
}

@Override
protected void onButtonCont_Button2Action(Component c, ActionEvent event) {

    System.out.println("button3 clicked");
}

(我创建的容器名为 ButtonCont..)在 StateMachine 或其他地方没有任何其他修改!

现在我启动了应用程序并单击了按钮 -​​ 但没有任何反应。

所以我

  1. 打开了 GUI Builder
  2. 选定的主窗体
  3. 依次选中三个Button
  4. 为每个人添加了 ActionListeners

现在我的状态机看起来像这样:

@Override
protected void onMain_Button2Action(Component c, ActionEvent event) {

    System.out.println("button3 -now- clicked");
}

@Override
protected void onMain_Button1Action(Component c, ActionEvent event) {

    System.out.println("button2 -now- clicked");
}

@Override
protected void onMain_ButtonAction(Component c, ActionEvent event) {

    System.out.println("button1 -now- clicked");
}

(除了前面的onButtonCont-方法)

启动应用程序并单击按钮会产生以下输出:

button1 -now- clicked
button3 -now- clicked
button2 -now- clicked

我做错了什么?

我自己找到了答案。

无需将容器添加到 "user defined" 部分下的表单,您只需添加一个嵌入式容器并将 select "embedded | [null]" 添加到您自己的容器