Printing different text each second (Timers etc)
Hello, let me just start with saying that this is my first post and I just registered, so forgive me if this is in the wrong section or if I'm doing something wrong.
I have created a simple game which writes a few lines of text if you press a "fight"-button. It basically says "Player hits enemy for 2 dmg" and "Enemy hits player for 3 dmg" and repeats that until either the player or the enemy has gone below 1 hp and lost. As of now, all the lines of text are printed instantly after pressing the button. What I want to do is have my program print "Player hits enemy for 2 dmg" after one second, and a second after that print "Enemy hits player for 3 dmg" and repeat for as long as the fight keeps going.
All this is done in a JFrame, with JTextAreas, if that makes any difference.
I've experimented a lot with "Sleep", "Wait" and different timers and I haven't been able to make it work correctly, so I came here to ask for help. Again, this is my first post and I just came to these forums so forgive me if I did something wrong.
Re: Printing different text each second (Timers etc)
I recommend you read through this tutorial: How to Use Swing Timers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)
Then post an SSCCE demonstrating what you've tried with the Swing Timer.
Re: Printing different text each second (Timers etc)
Quote:
Originally Posted by
KevinWorkman
Thanks! I'll try this.