【问题标题】:Get Component From Gui Form从 Gui 表单获取组件
【发布时间】:2018-08-31 14:06:02
【问题描述】:

我是 codenameone 的新手。

我在新的 Gui Builder 中使用 ClassName AppSplash 制作了一个表单组件。 在那个 AppSplash 类中,来自 Gui 我有两个容器“Container1”和“Container2”。 在 Container2 中,我有一个名为“Memebers_Count”的标签。 我从另一个类实例化这个 AppSplash,比如

AppSlpash as = new AppSplash()

如何访问标签“Members_Count”以更改其显示的文本?

我试图做一些类似的事情 as.getComponentAt(0).getComponentAt(1)

但是第二个 getComponentAt(1) 在 Netbeans 中显示为 erron,并显示“找不到符号:getComponentAt(1)”,而第一个 getComponentAt 没有错误。

感谢任何帮助

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    做这样的事情通常被认为是不好的。您将依赖第二种形式的结构,对结构的任何微小更改都可能破坏它。

    正确的解决方案是在第一个表单中添加一个方法,例如:

    public void setMemberCount(int value) {
       gui_Members_Count.setText("" + value);
    }
    

    然后在第二种形式中做:

    secondForm.setMemberCount(value);
    

    您可能需要转换为正确的类型,例如((SecondFormClassName)secondForm).setMemberCount(value);.

    【讨论】:

      猜你喜欢
      • 2016-12-30
      • 1970-01-01
      • 2020-04-04
      • 2013-07-07
      • 1970-01-01
      • 2016-09-24
      • 2011-08-16
      • 1970-01-01
      • 2014-01-21
      相关资源
      最近更新 更多