gpt4 book ai didi

codenameone - 新代号 One 准系统项目开始新项目

转载 作者:行者123 更新时间:2023-12-04 12:54:38 25 4
gpt4 key购买 nike

我现在注意到通过 https://start.codenameone.com/ 获得的源 Java 代码发生了根本性的变化。
显然我已经习惯用 init()、start()、stop()、destroy() 方法编码,我不知道如何处理这些新代码。它在某处记录了吗?我在博客中没有看到任何内容。谢谢
Lifecycle 的 javadoc ( https://www.codenameone.com/javadoc/com/codename1/system/Lifecycle.html ) 不是很有帮助。它只是指出:

Optional helper class that implements the Codename One lifecyclemethods with reasonable default implementations to help keep samplecode smaller.


所以下面的代码只是一个例子,我需要删除,然后手动插入通常的init()、start()、stop()和destroy()方法?
public class MyDownloader extends Lifecycle {
@Override
public void runApp() {
Form hi = new Form("Hi World", BoxLayout.y());
Button helloButton = new Button("Hello World");
hi.add(helloButton);
helloButton.addActionListener(e -> hello());
hi.getToolbar().addMaterialCommandToSideMenu("Hello Command",
FontImage.MATERIAL_CHECK, 4, e -> hello());
hi.show();
}

private void hello() {
Dialog.show("Hello Codename One", "Welcome to Codename One", "OK", null);
}

}

最佳答案

这在这里讨论:https://www.reddit.com/r/cn1/comments/opifd6/a_new_approach_for_the_lifecycle_main_class/
请注意,生命周期方法仍然存在,您可以根据需要覆盖它们,但在大多数情况下,您实际上并不需要:

When we started Codename One we copied the convention in Java ofhaving a very verbose lifecycle class. This seemed like a good andpowerful approach when we just started. The thing about core decisionslike that is that you end up accepting them as dogma even when youyourself made them.

That was just stupid and with my recent commit this should be fixed.With this your main class can derive from the new Lifecycle object andyou would be able to remove a lot of boilerplate. E.g. this would bethe new "Hello World":

public class MyApp extends Lifecycle {
public void runApp() {
Form hello = new Form("Hello", BoxLayout.y());
hello.add(new Label("Hello World"));
hello.show();
}
}

That removes a lot of the stuff most of us don't touch in thelifecycle class while still allowing us to customize it if we need todo that.

关于codenameone - 新代号 One 准系统项目开始新项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68727242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com