How would I implement multiple timers into one class? The code below only shows one timer that I'm using but I wish to add another one. I did try earlier on but I never quite figured out how I would have a separate method for it.Is it possible? Thanks.

Having multiple timers is very unreliable, as they may easily go out of sync. At best, some things might go slightly slower than other things. At worst, it crashes your game because something happened in an unexpected order. Go with a game loop and have it call player.update(), along with all other update methods (NPCs, bullets, animations, whatever you have in the game).

While using the gameloop for this kind of stuff is the Right Thing (TM), I just want to answer the question for other circumstances this is needed (like in Swing) - you can bind methods to Listeners with "anonymous inner classes" (since there are no closures or lambdas yet - Java 8 might change this):

A lot of people like to use multiple ActionListener's, I never understood why personally. I had professors teaching it this way in school, even when you have like 15 different things that can throw ActionEvent's (in a Swing interface).

AlotofpeopleliketousemultipleActionListener's, I never understood why personally.

Using anonymous inner classes is just one way to avoid implementing the Listener interface in the class that should receive the events, since it is not always desirable to clutter the api of your class with public Listener callbacks, since they are internal implementation details and should not be able to get called directly.

AlotofpeopleliketousemultipleActionListener's, I never understood why personally.

Using anonymous inner classes is just one way to avoid implementing the Listener interface in the class that should receive the events, since it is not always desirable to clutter the api of your class with public Listener callbacks, since they are internal implementation details and should not be able to get called directly.

Still doesn't explain why you need 15 different anonymous classes for 15 different objects that generate action events. Just make one handler. It's cleaner, and you can standardize what you do with it like for example perform all actions on the main thread rather than the EDT.

Still doesn't explain why you need 15 different anonymous classes for 15 different objects that generate action events.

I simply find it easier to read (and even shorter to write), especially when you have more than just ActionListeners. With your approach you will end up with a lot of different dispatcher methods with a lot of if/else blocks. If you like that, fine...

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org