gpt4 book ai didi

java - 代号 One Timer 问题

转载 作者:行者123 更新时间:2023-12-02 06:08:25 26 4
gpt4 key购买 nike

我正在尝试在 Codename One 中使用计时器,但它只有“UITimer”,我似乎无法弄清楚也找不到任何示例。

所以我尝试了 Swing 计时器,但它给了我错误:

codename1.ui.events.ActionListener cannot be converted to java.awt.event.ActionListener

使用此代码

tim = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent evt) {

}
});

最佳答案

您应该删除 awt 的导入,并且永远不要导入这些类。

UITimer 适用于 Action 事件,但您使用了计时器。如果您使用 javax.swing 中的 Timer,则删除所有这些导入,这也是一个错误。

如果您使用 java.util.Timer,则应该使用 TimerTask 而不是操作监听器。这是 NetBeans 的一个问题,它不允许设置单独的项目 bootclasspath,因此会导入我们不支持且不会编译的类。

UITimer 示例位于开发人员指南的末尾:http://www.codenameone.com/developer-guide.html以及整个讨论论坛:https://groups.google.com/forum/#!searchin/codenameone-discussions/UITimer

关于java - 代号 One Timer 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22097507/

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