0

need an example, how to use timer in SwingWorker ? because it impossible to add an ActionListener to my Timer like that !

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

    @Override
    public void actionPerformed(ActionEvent ae) {

    }
});

Message Error : The constructor Timer(int, new ActionListener(){}) is undefined

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
serabile
  • 329
  • 3
  • 11
  • `Timer in SwingWorker ?`... AFAIK, you use `javax.swing.Timer` for short tasks, that needs to be done on the EDT (though you can also use java.util.Timer with some `STRINGS attached` on it's proper usage), while you use `SwingWorker` for a long running background task, whose output is something you wanted to convey on the EDT. You don't use them together. – nIcE cOw Jan 05 '13 at 05:26
  • Here is one wonderful [example](http://stackoverflow.com/a/11282106/1057230) by @mKorbel. Here is one [example](http://stackoverflow.com/a/10051684/1057230). – nIcE cOw Jan 05 '13 at 05:31
  • One more wonderful [example](http://stackoverflow.com/a/7748847/1057230). – nIcE cOw Jan 05 '13 at 05:37

1 Answers1

5

There is nothing wrong in your source, looks like you are importing different Timer class. Are your using javax.swing.Timer. Refer the API document here.

May be you had imported javax.management.timer.Timer or java.util.Timer

Jayamohan
  • 12,734
  • 2
  • 27
  • 41