aboutsummaryrefslogtreecommitdiff
path: root/test/ch
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-05-09 22:52:56 +0200
committerPacien TRAN-GIRARD2016-05-09 22:52:56 +0200
commite85032012f1d5ded1b6a49a88d345cc60a6ac88b (patch)
tree3e8122814fd0c4e9094a16c2e3bf53b8ce7d728b /test/ch
parentd9854415ffb5affb5021146a61bf76ebec0769e2 (diff)
downloadxblast-e85032012f1d5ded1b6a49a88d345cc60a6ac88b.tar.gz
Properly handle keyboard events
Diffstat (limited to 'test/ch')
-rw-r--r--test/ch/epfl/xblast/simulation/GraphicalSimulation.java14
1 files changed, 8 insertions, 6 deletions
diff --git a/test/ch/epfl/xblast/simulation/GraphicalSimulation.java b/test/ch/epfl/xblast/simulation/GraphicalSimulation.java
index 8009d9f..9329cc7 100644
--- a/test/ch/epfl/xblast/simulation/GraphicalSimulation.java
+++ b/test/ch/epfl/xblast/simulation/GraphicalSimulation.java
@@ -11,6 +11,7 @@ import ch.epfl.xblast.server.Level;
11import ch.epfl.xblast.server.painter.BoardPainter; 11import ch.epfl.xblast.server.painter.BoardPainter;
12 12
13import javax.swing.*; 13import javax.swing.*;
14import java.awt.*;
14import java.awt.event.KeyEvent; 15import java.awt.event.KeyEvent;
15import java.util.Collections; 16import java.util.Collections;
16import java.util.HashMap; 17import java.util.HashMap;
@@ -48,27 +49,28 @@ public class GraphicalSimulation extends Simulation {
48 return GameStateDeserializer.deserialize(serializedGameState); 49 return GameStateDeserializer.deserialize(serializedGameState);
49 } 50 }
50 51
51 private static JFrame buildFrame(XBlastComponent gui) { 52 private static JFrame buildFrame(Container content) {
52 JFrame frame = new JFrame(); 53 JFrame frame = new JFrame();
53 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 54 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
54 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 55 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
55 frame.setVisible(true); 56 frame.setVisible(true);
56 57
57 frame.setContentPane(gui); 58 frame.setContentPane(content);
58 frame.pack(); 59 frame.pack();
59 return frame; 60 return frame;
60 } 61 }
61 62
62 private void attachKeyboardHandler(JFrame frame) { 63 private void attachKeyboardHandler(Component comp) {
63 frame.addKeyListener(new KeyboardEventHandler(buildPlayerActionMap(), PLAYER_ACTION_CONSUMER)); 64 comp.addKeyListener(new KeyboardEventHandler(buildPlayerActionMap(), PLAYER_ACTION_CONSUMER));
64 frame.requestFocusInWindow(); 65 comp.requestFocusInWindow();
65 } 66 }
66 67
67 private final XBlastComponent gui; 68 private final XBlastComponent gui;
68 69
69 private GraphicalSimulation() { 70 private GraphicalSimulation() {
70 this.gui = new XBlastComponent(); 71 this.gui = new XBlastComponent();
71 attachKeyboardHandler(buildFrame(this.gui)); 72 buildFrame(this.gui);
73 attachKeyboardHandler(this.gui);
72 } 74 }
73 75
74 @Override 76 @Override