|
-
Program in Infinite Loop Unable to Handle User Input
Hi all,
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)
{
while (true)
{
this.setAlarm(alarmed, delay);
}
}
public void setAlarm(Alarmed alarmed, double delay)
//delay is in milliseconds
{
timer.start();
while (timer.stop() < delay)
{
}
alarmed.alarmAction();
}
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?
Thanks,
David
Similar Threads
-
By Ervin Rodriguez in forum Database
Replies: 1
Last Post: 05-16-2003, 08:45 AM
-
By Miroslav St. Jeliaskoff in forum .NET
Replies: 0
Last Post: 10-01-2002, 02:37 PM
-
Replies: 1
Last Post: 05-22-2002, 07:48 AM
-
By Metal Maniac in forum Java
Replies: 2
Last Post: 02-12-2001, 12:14 AM
-
Replies: 0
Last Post: 07-17-2000, 03:26 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks