Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

speed is increasing unexpectedly

 
budsy remo
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi , it's budsy again . I am having a strange problem .I have designed a game. In this game i am using a timer . This timer is associated with an actionlistener . Whenever you click on the ball the ball starts moving up till it hits the ceiling and starts moving towards the floor . Now no where in the code am i reducing the interval because of which the speed will increase but now the strange thing is that
whenever i click on the ball, it starts moving up(like it's supposed to) but the speed also increases . Can somebody explain why ?





 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which method are you constructing a Timer?

What happens each time that method runs?
 
budsy remo
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am constructing the timer in the mouseClicked() method . Maybe that's the problem that the previous thread is never stopped ?
In that method Timer notifies the class that is implementing the actionlistener after some intervals and that class's actionPerformed checks the boundaries(Y coordinate)
and accordingly increases or decrease the value.
 
budsy remo
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe that's the problem that the previous thread is never stopped ?

thanks a lot the problem has been resolved ,turns out that was the problem but just another question , is timer a thread ?
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another question , is timer a thread ?

The answer to that is in the API. Make a habit of reading the API for any unfamiliar class, it'll serve you well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic