interrupt sleeping thread by mouse action
Hello, I'm developing a computer desk game like checkers (swing application). Now I can't solve up one of my last problems. I have to implement user-user, user-computer and computer-computer game. The first two of them are simple and the last, computer-computer, is problem to me.
My application has menu and toolbar, where the settings of the game items are set up. If I choose computer-computer game in settings, everything is correct. Computer starts to play and answers again. But If I want to interrupt the play, it is impossible. I'd like to click the button in the toolbar, or the item in the menu bar, but the game won't let me nor click the button neither expand the menu.
I have written something like this:
Code:
// loop while one of the players isn't set to 'user'
while(!(getPlayer1().equals("user") || getPlayer2().equals("user"))) {
Thread.sleep(4000); // time for interrupt computer-computer game
String[] bestMove = generateBestMove(); // generate best move with given difficulty
move(bestMove[0], bestMove[1]); // put the move through
repaintBoard(); // repaint the board
if (Referee.checkGameEnd()) {
break;
}
}
I need to interrupt this game by click the button. How can I put it through? Thank you.