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);
|
background.setBackground(Color.BLACK);
|
||||||
|
|
||||||
startNewGame = new JButton("START NEW GAME");
|
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.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 -70,200,30);
|
||||||
startNewGame.setActionCommand("startNewGame");
|
startNewGame.setActionCommand("startNewGame");
|
||||||
startNewGame.addActionListener(new ActionListener() {
|
startNewGame.addActionListener(actionEvent -> {
|
||||||
@Override
|
cleanUp();
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
game.add(freeMove);
|
||||||
cleanUp();
|
game.requestFocus();
|
||||||
game.add(freeMove);
|
freeMove.start(true);
|
||||||
freeMove.setFocusable(true);
|
|
||||||
freeMove.start(true);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
loadSavedGame = new JButton("LOAD SAVED GAME");
|
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.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2,200,30);
|
||||||
loadSavedGame.setActionCommand("loadSavedGame");
|
loadSavedGame.setActionCommand("loadSavedGame");
|
||||||
loadSavedGame.addActionListener(new ActionListener() {
|
loadSavedGame.addActionListener(actionEvent -> {
|
||||||
@Override
|
cleanUp();
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
game.add(freeMove);
|
||||||
cleanUp();
|
game.requestFocus();
|
||||||
game.add(freeMove);
|
freeMove.start(false);
|
||||||
freeMove.setFocusable(true);
|
|
||||||
freeMove.start(false);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
exitGame = new JButton("EXIT GAME");
|
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.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 + 70,200,30);
|
||||||
exitGame.setActionCommand("exitGame");
|
exitGame.setActionCommand("exitGame");
|
||||||
exitGame.addActionListener(new ActionListener() {
|
exitGame.addActionListener(actionEvent -> game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING)));
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
|
||||||
game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
add(startNewGame);
|
add(startNewGame);
|
||||||
add(loadSavedGame);
|
add(loadSavedGame);
|
||||||
@ -72,7 +61,12 @@ public class WindowOfMenu extends JLayeredPane {
|
|||||||
|
|
||||||
private void cleanUp() {
|
private void cleanUp() {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
startNewGame.removeActionListener(startNewGame.getActionListeners()[0]);
|
||||||
|
loadSavedGame.removeActionListener(loadSavedGame.getActionListeners()[0]);
|
||||||
|
exitGame.removeActionListener(exitGame.getActionListeners()[0]);
|
||||||
game.remove(this);
|
game.remove(this);
|
||||||
|
menu().revalidate();
|
||||||
|
menu().repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public WindowOfMenu menu() { return this; }
|
public WindowOfMenu menu() { return this; }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user