Skip to content
Advertisement

How to pause and resume a simple game in Java

i made simple game by java , it’s about “tennis background” and “tennis ball” , and the ball is randomally move automatically ,

my game consist of two file , 1st file fore Jpanel , and 2nd file for JFrame ,

my question is : i need to control of “stopping and resuming” the ball by clicking the mouse , i tried to put wait() during thread running loop , but it’s faild , i don’t know what is the reason ! , so please review my code and then tell me what is the wrong , and what is the true method of “pause&resume” thread in my simple game !

tennis.java file (which contain the thread):

JavaScript

Tennis3D.java file(frame for starting the game and define the thread) :

JavaScript

Thank you for your help 🙂

Advertisement

Answer

This is piggy-backing on what Nerdtron wrote in the comment above. Typically a game loop looks like this

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement