Program in Infinite Loop Unable to Handle User Input
I am working on a simple game in which the player moves a paddle up and down to keep a bouncing ball from going out of bounds. The user moves the paddle by the pressing and dragging on the paddle (graphically shown as a rectangle) with the mouse. To keep the ball in constant motion, I created an Alarm class which notifies the top-level class in the program when the ball needs to be moved.
public void setEndlessAlarm(Alarmed alarmed, double delay)
public void setAlarm(Alarmed alarmed, double delay)
//delay is in milliseconds
while (timer.stop() < delay)
The problem is that when the method setEndlessAlarm() is called, the paddle can no longer be moved. In fact, no user input is handled. The window cannot even be closed; to end the program, I must use Eclipse's Terminate button.
To deal with the problem, I tried to use threading, since I hear that multithreading allows several events to run simultaneously. So, I set up a thread to initialize the listener, and a thread to keep the ball moving. The output was the same. I also tried using yield(), wait(), sleep(), and other Thread methods to give an opportunity for the user input to be handled. It could just be that I do not know how to properly implement threading.
So, the bottom line is, how can I receive and handle user input while still having the ball moving?