Christoforos
Christoforos

Reputation: 723

Get Component From Gui Form

I am new on codenameone.

I have make a Form Component at the new Gui Builder with ClassName AppSplash. In that AppSplash Class, from the Gui I have two Containers "Container1" and "Container2". Inside Container2 I have a Label named "Memebers_Count". I instantiate this AppSplash from another class like

AppSlpash as = new AppSplash()

How can I access the Label "Members_Count" so as to change its displayed text?

I tried to do somethind like as.getComponentAt(0).getComponentAt(1)

but the second getComponentAt(1) is shown as erron in Netbeans with the notice "cannot find symbol: getComponentAt(1)", while the first getComponentAt is not erroneus.

Any help is aprreciated

Upvotes: 2

Views: 93

Answers (1)

Shai Almog
Shai Almog

Reputation: 52770

Doing something like that is generally considered bad. You would rely on the structure of the second form and any minor change to the structure might break it.

The right solution would be adding a method to the first form such as:

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

Then in the second form do:

secondForm.setMemberCount(value);

You might need to cast to the right type e.g. ((SecondFormClassName)secondForm).setMemberCount(value);.

Upvotes: 0

Related Questions