Added called to requestFocus() in GameApplet.init() and GameThread.run()

refs #11

The brute force method of requesting focus seems to be the only
fix/workaround that I could find. However it doesn't seem to cause any
preformance issues

Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-04-22 14:59:07 -04:00
parent 390e962462
commit e835d3c795
2 changed files with 23 additions and 0 deletions

View File

@@ -213,6 +213,12 @@ public class AsteroidGameThread extends Thread {
while (true){
if(isStarted) {
/*
* brute force focus,
* this seems to be the only fix I can find, for now
*/
mGameApplet.requestFocus();
/*
* increment time
*/

View File

@@ -216,6 +216,9 @@ public class GameApplet extends JApplet implements ActionListener, KeyListener {
repaint();
mGameThread.newGame();
this.setFocusable(true);
this.requestFocus();
}
/**
@@ -254,6 +257,20 @@ public class GameApplet extends JApplet implements ActionListener, KeyListener {
@Override
public void keyTyped(final KeyEvent e) {
switch(e.getKeyCode()){
/*
* [Enter]
* Start of pause the game
*/
case KeyEvent.VK_ENTER:
if(mGameThread.isStarted)
mGameThread.pauseGame();
else
mGameThread.startGame();
break;
}
driveShip(e, true);
}
/**