• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Ending a Timer within itself

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody !


I've got a little problem concerning my program :
I want to end a timer when a certain value reaches zero, but it keeps telling me "local variable timer1 is accessed from within inner class and needs to be declared final", but I don't want to make it final !
I tried many differnet ways, and in the end made my code exactly like this one (or so I think) : http://www.java2s.com/Code/JavaAPI/javax.swing/Timerstop.htm but it still doesn't work...
It's lines 69 and 78.
Here is my code :



Thank you for your help !

Oracion
 
Rancher
Posts: 3265
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Why don't you have a problem with the "dinozHP" and "monsterHP" variables?

In other words how are those variables defined differently than the "timer1" variable?
 
Sheriff
Posts: 22650
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't you use e.getSource(), after casting it to Timer?
 
Jean Fontaine
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow !
Thanks a lot !
I just had to add "Timer timer1;" at the beginning !
I didn't really get the e.getsource thing, but I'll try to find more about it tomorrow !
Thanks again both of you !

Oracion
 
Quick! Before anybody notices! Cover it up with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic