diff --git a/src/main/java/Game.java b/src/main/java/Game.java index b0f38af..da23528 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -78,6 +78,6 @@ public class Game extends JFrame { } - public Game game() {return this; } + public Game game() {return this;} } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java index 9acf783..b7bfe30 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java @@ -26,43 +26,32 @@ public class WindowOfMenu extends JLayeredPane { background.setBackground(Color.BLACK); startNewGame = new JButton("START NEW GAME"); - startNewGame.setFocusable(false); + //startNewGame.setFocusable(false); startNewGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 -70,200,30); startNewGame.setActionCommand("startNewGame"); - startNewGame.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - cleanUp(); - game.add(freeMove); - freeMove.setFocusable(true); - freeMove.start(true); - } + startNewGame.addActionListener(actionEvent -> { + cleanUp(); + game.add(freeMove); + game.requestFocus(); + freeMove.start(true); }); loadSavedGame = new JButton("LOAD SAVED GAME"); - loadSavedGame.setFocusable(false); + //loadSavedGame.setFocusable(false); loadSavedGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2,200,30); loadSavedGame.setActionCommand("loadSavedGame"); - loadSavedGame.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - cleanUp(); - game.add(freeMove); - freeMove.setFocusable(true); - freeMove.start(false); - } + loadSavedGame.addActionListener(actionEvent -> { + cleanUp(); + game.add(freeMove); + game.requestFocus(); + freeMove.start(false); }); exitGame = new JButton("EXIT GAME"); - exitGame.setFocusable(false); + //exitGame.setFocusable(false); exitGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 + 70,200,30); exitGame.setActionCommand("exitGame"); - exitGame.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING)); - } - }); + exitGame.addActionListener(actionEvent -> game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING))); add(startNewGame); add(loadSavedGame); @@ -72,7 +61,12 @@ public class WindowOfMenu extends JLayeredPane { private void cleanUp() { setVisible(false); + startNewGame.removeActionListener(startNewGame.getActionListeners()[0]); + loadSavedGame.removeActionListener(loadSavedGame.getActionListeners()[0]); + exitGame.removeActionListener(exitGame.getActionListeners()[0]); game.remove(this); + menu().revalidate(); + menu().repaint(); } public WindowOfMenu menu() { return this; }