0
How to use stop() in java swing Timer class ?
I want to repeat some code with Timer class in java. Here's the code : Timer t = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent evt) { // Do action if(workIsDone) { t.stop(); } } } ); t.start(); When i compile it i am getting error: variable t might not have been initialized t.stop(); How to solve this ? I think i am getting this because of anonymous inner class but i am unable to solve it :(
3 odpowiedzi
+ 1
declare t as class member, not local
+ 1
yes. t declare outside...
Am not sure but try Timer.stop(); stop(); simply..
Edit : Kuber Acharya use timer.cancel() instead..
0
zemiak Solved! Thank you:)