Focus fix
This commit is contained in:
parent
28da4d4995
commit
093a2d7ab7
@ -78,6 +78,6 @@ public class Game extends JFrame {
|
||||
|
||||
}
|
||||
|
||||
public Game game() {return this; }
|
||||
public Game game() {return this;}
|
||||
}
|
||||
|
||||
|
||||
@ -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) {
|
||||
startNewGame.addActionListener(actionEvent -> {
|
||||
cleanUp();
|
||||
game.add(freeMove);
|
||||
freeMove.setFocusable(true);
|
||||
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) {
|
||||
loadSavedGame.addActionListener(actionEvent -> {
|
||||
cleanUp();
|
||||
game.add(freeMove);
|
||||
freeMove.setFocusable(true);
|
||||
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; }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user