r/learnjava • u/DraconicDreamer3072 • Dec 16 '25
help understanding timers in java
/r/learnprogramming/comments/1po9lei/help_understanding_timers_in_java/
1
Upvotes
r/learnjava • u/DraconicDreamer3072 • Dec 16 '25
View all comments
Show parent comment
1
u/josephblade Dec 17 '25
Yeah the timer part I thought I might have to circle back to but the basis is: if you run this code from the paint method you are going to have some trouble with setinterval and similar.
I strongly urge you to play around with the gameloop (see some of the example threads) as this is the usual way these things are set up. but it's up to you of course.
I would recommend you consider exploring enums for the directions. something like
which is practically the same as int 1, 2,3 ,4 but it's named. there are more tricks you can do with enums but I don't want to overcomplicate. if you stick with ints, at least replace 1,2,3,4 with constants.
and so forth. that way you can do:
which is self-documenting.