Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using thread.sleep in a keylistener... yeah...

843806Dec 21 2008 — edited Dec 21 2008
How might I do this in a keylistener properly to use thread.sleep if the while condition is based on the key pressed (spacebar)?

//PROBLEM HERE - THIS IS IN A KEY LISTENER
		while(e.getKeyCode()!=32) 
		{
			try 
			{
				//Set players last square to red/blue
				gridArray[player1.getY()][player1.getX()].setIcon(redImg);
				gridArray[player2.getY()][player2.getX()].setIcon(blueImg);
				
				player1.update(player1.getDirection());
				player2.update(player2.getDirection());
				
				Thread.sleep(500);
			}
			catch (InterruptedException ex) 
			{
				System.out.println("Timer Error");//just break through
			}
		}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 18 2009
Added on Dec 21 2008
16 comments
492 views