diff --git a/app/src/main/java/chess/simplerender/Window.java b/app/src/main/java/chess/simplerender/Window.java index 958d284..8f75786 100644 --- a/app/src/main/java/chess/simplerender/Window.java +++ b/app/src/main/java/chess/simplerender/Window.java @@ -28,16 +28,19 @@ import chess.model.Piece; public class Window extends JFrame implements OutputSystem { private final JLabel cells[][]; + private final JLabel displayText; private final CommandExecutor commandExecutor; private Coordinate lastClick = null; public Window(CommandExecutor commandExecutor) { this.cells = new JLabel[8][8]; + this.displayText = new JLabel(); this.commandExecutor = commandExecutor; - setSize(800, 800); + setSize(800, 870); setVisible(true); - setDefaultCloseOperation(EXIT_ON_CLOSE); + setLocationRelativeTo(null); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); } private CommandResult sendCommand(Command command) { @@ -53,8 +56,14 @@ public class Window extends JFrame implements OutputSystem { } private void buildBoard() { - JPanel content = new JPanel(new GridLayout(8, 8)); + JPanel content = new JPanel(); + JPanel grid = new JPanel(new GridLayout(8, 8)); + + content.add(this.displayText); + content.add(grid); + setContentPane(content); + for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { JLabel label = new JLabel(); @@ -72,7 +81,7 @@ public class Window extends JFrame implements OutputSystem { } }); - content.add(label); + grid.add(label); } } updateBoard(); @@ -151,13 +160,14 @@ public class Window extends JFrame implements OutputSystem { @Override public void playerTurn(chess.model.Color color) { - System.out.println("C'est au tour de " + color); + this.displayText.setText("C'est au tour de " + color); } @Override public void winnerIs(chess.model.Color color) { SwingUtilities.invokeLater(() -> { JOptionPane.showMessageDialog(this, "Victoire de " + color); + this.dispose(); }); } @@ -197,9 +207,6 @@ public class Window extends JFrame implements OutputSystem { @Override public void promotePawn(Coordinate pieceCoords) { SwingUtilities.invokeLater(() -> { - // String result = JOptionPane.showInputDialog(this, "Choisissez le type !"); - // sendCommand(new PromoteCommand(PromoteType.Queen, pieceCoords)); - String result = null; Object[] possibilities = new Object[PromoteType.values().length];