简体   繁体   English

如何在SwingWorker中使用计时器

[英]how to use timer with SwingWorker

need an example, how to use timer in SwingWorker ? 需要一个例子,如何在SwingWorker中使用计时器? because it impossible to add an ActionListener to my Timer like that ! 因为不可能像这样将ActionListener添加到我的Timer中!

private Timer timer = new Timer(100, new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent ae) {

    }
});

Message Error : The constructor Timer(int, new ActionListener(){}) is undefined 消息错误: 构造函数Timer(int,new ActionListener(){})未定义

There is nothing wrong in your source, looks like you are importing different Timer class. 您的源代码没有错,看起来您正在导入其他Timer类。 Are your using javax.swing.Timer . 您在使用javax.swing.Timer Refer the API document here. 请在此处参阅API文档

May be you had imported javax.management.timer.Timer or java.util.Timer 可能是您导入了javax.management.timer.Timerjava.util.Timer

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

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