How to use variables to refer to Components in codename one?

♀尐吖头ヾ 提交于 2019-12-06 10:35:42

Yes you can do that, but not advisable.

The danger of it is when you have 2 components with the same name on different forms, this may reference wrong component and may be hard to debug.

If you sure can deal with the above, you can declare and initiate the variables inside Statemachine class but outside of all methods as a private global variable.

public class Statemachine ... {

    private Container c = findContainer();
    private Tabs t = findTabs(); 

    initVars () {

    }

    ....
}

You can't do that in the current GUI builder since the current GUI builder creates forms dynamically and discards them during navigation.

The new GUI builder uses a completely different architecture and will work exactly like that: 1 class per one UI form. So you will have variables for every field.

You can see this in action here.

Note that at this time the GUI builder is still in pre-beta stage although we are heavily committed to it and its architecture.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!