summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2013-11-14 21:12:26 +0100
committerPeter Wu <lekensteyn@gmail.com>2013-11-14 21:12:26 +0100
commit397dda2d8c2e79eb14a883cb3260b7f2e67b7086 (patch)
tree31bbca1ef21340c9ecef041c358b3d8aea95dfe2
parent943e0d8bb6f808966f9ec783a5826fe2840c6545 (diff)
download2iv60-robots-397dda2d8c2e79eb14a883cb3260b7f2e67b7086.tar.gz
Allow Escape to Quit the application
-rw-r--r--src/RobotRace.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/RobotRace.java b/src/RobotRace.java
index f9c1a0b..4384b38 100644
--- a/src/RobotRace.java
+++ b/src/RobotRace.java
@@ -1,6 +1,10 @@
+import java.awt.KeyEventDispatcher;
+import java.awt.KeyboardFocusManager;
+import java.awt.event.KeyEvent;
import javax.media.opengl.GL;
import static javax.media.opengl.GL2.*;
+import javax.swing.UIManager;
import robotrace.Base;
import robotrace.Vector;
@@ -520,6 +524,18 @@ public class RobotRace extends Base {
* the RobotRace implementation.
*/
public static void main(String args[]) {
+ // Being able to exit by pressing Escape would be nice.
+ KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent e) {
+ if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ System.err.println("Exiting...");
+ System.exit(0);
+ return true;
+ }
+ return false;
+ }
+ });
RobotRace robotRace = new RobotRace();
}