对于我的主应用程序,我需要一个用于导航目的的自定义容器,请参阅 here (堆栈溢出)。
由于发布的解决方案对我不起作用(我尝试使用简单的 System.out.println),我开始了一个新项目来了解容器嵌入如何工作,但它没有按我预期的方式工作。
所以新的应用程序是橙色的 Hi World 应用程序。
我在 GUI 设计器中创建了一个新的空白容器并添加了 3 个按钮。
- 我在 GUI 设计器中创建了一个新的空白容器并添加了 3 个按钮。
- 我在容器内向它们添加了一个actionListener
- 我将容器添加到表单
我的状态机看起来像这样:
@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 或其他地方没有进行任何其他修改!
现在我启动了应用程序并单击了按钮 - 但什么也没发生。
所以我
- 打开 GUI 构建器
- 选定的主窗体
- 依次选择了三个按钮
- 为每个添加了 ActionListener
现在我的状态机看起来像这样:
@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
我做错了什么?
最佳答案
我自己找到了答案。
无需将容器添加到“用户定义”部分下的表单中,您只需添加一个嵌入式容器并选择“embedded | [null]”到您自己的容器
关于java - 在 CodenameOne 中创建容器时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35196961/