File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Ending a Timer within itself Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Ending a Timer within itself" Watch "Ending a Timer within itself" New topic

Ending a Timer within itself

Jean Fontaine

Joined: Apr 12, 2011
Posts: 12
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) : but it still doesn't work...
It's lines 69 and 78.
Here is my code :

Thank you for your help !

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2266

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?
Rob Spoor

Joined: Oct 27, 2005
Posts: 19911

Can't you use e.getSource(), after casting it to Timer?

How To Ask Questions How To Answer Questions
Jean Fontaine

Joined: Apr 12, 2011
Posts: 12
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 !

I agree. Here's the link:
subject: Ending a Timer within itself