diff options
-rw-r--r-- | src/ch/epfl/xblast/client/KeyboardEventHandler.java | 2 | ||||
-rw-r--r-- | test/ch/epfl/xblast/simulation/GraphicalSimulation.java | 14 |
2 files changed, 9 insertions, 7 deletions
diff --git a/src/ch/epfl/xblast/client/KeyboardEventHandler.java b/src/ch/epfl/xblast/client/KeyboardEventHandler.java index a0d3848..2060959 100644 --- a/src/ch/epfl/xblast/client/KeyboardEventHandler.java +++ b/src/ch/epfl/xblast/client/KeyboardEventHandler.java | |||
@@ -37,7 +37,7 @@ public class KeyboardEventHandler extends KeyAdapter { | |||
37 | * @param e event (pressed key) | 37 | * @param e event (pressed key) |
38 | */ | 38 | */ |
39 | @Override | 39 | @Override |
40 | public void keyTyped(KeyEvent e) { | 40 | public void keyPressed(KeyEvent e) { |
41 | PlayerAction act = this.playerActionMap.get(e.getKeyCode()); | 41 | PlayerAction act = this.playerActionMap.get(e.getKeyCode()); |
42 | 42 | ||
43 | if (Objects.nonNull(act)) | 43 | if (Objects.nonNull(act)) |
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; | |||
11 | import ch.epfl.xblast.server.painter.BoardPainter; | 11 | import ch.epfl.xblast.server.painter.BoardPainter; |
12 | 12 | ||
13 | import javax.swing.*; | 13 | import javax.swing.*; |
14 | import java.awt.*; | ||
14 | import java.awt.event.KeyEvent; | 15 | import java.awt.event.KeyEvent; |
15 | import java.util.Collections; | 16 | import java.util.Collections; |
16 | import java.util.HashMap; | 17 | import 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 |