简体   繁体   English

如何使用Codename One访问.res文件中的UI组件?

[英]How do I access UI components in a .res file with Codename One?

I'm new to Codename one, and I'm trying to build a simple application where when you press a button, a label changes its text. 我是Codename的新手,我正在尝试构建一个简单的应用程序,当您按下按钮时,标签会更改其文本。 I decided to utilize the UI builder CodenameOne provides because it is simple and easy to use, much less hassle than coding a UI by hand. 我决定使用CodenameOne提供的UI构建器,因为它简单易用,比手工编写UI更麻烦。 I created a button and a label. 我创建了一个按钮和一个标签。 I pressed the 'Action Event' button to create a listener method for the button. 我按下“动作事件”按钮为按钮创建一个侦听器方法。 I went to the listener method to put in my code that changes the label. 我去了监听器方法来放入我的代码来改变标签。 But the problem is that I don't know how to access the label in the .res file to edit the text. 但问题是我不知道如何访问.res文件中的标签来编辑文本。 So my question is, How do I change the stuff in the .res file from my code? 所以我的问题是, 如何从我的代码中更改.res文件中的内容? I searched the Codename One site, but I couldn't find anything. 我搜索了Codename One网站,但我找不到任何东西。 I looked at this question , but it didn't seem to address my problem. 我看了这个问题 ,但似乎没有解决我的问题。

I feel like the answer is probably right under my nose, so I apologize if this is a noob question, but I've been looking for an answer for a few days now. 我觉得答案可能就在我的鼻子底下,所以如果这是一个菜鸟问题我会道歉,但我现在一直在寻找答案。

Take a look at this video , helped me a lot regarding this. 看看这个视频 ,对此有很大帮助。

Anyway a small example, assuming you have a Button named "Button1" in your UI. 无论如何,假设你的UI中有一个名为“Button1”的Button,这是一个小例子。 You can access it in your StateMachine under findButton1() 您可以在findButton1()下访问它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM