Browse Source

tictactoe: refactored generateGUI method

tictactoe
Malte Schellhardt 3 years ago
committed by Lorenz Hohmann
parent
commit
82890b25aa
  1. 17
      src/main/java/de/tims/tictactoe/GameLogic.java

17
src/main/java/de/tims/tictactoe/GameLogic.java

@ -12,6 +12,9 @@ public class GameLogic {
private static final char PLAYER_2 = 'o'; private static final char PLAYER_2 = 'o';
private char[][] board; private char[][] board;
private final char[] occupiedFields = { PLAYER_1, PLAYER_2 }; private final char[] occupiedFields = { PLAYER_1, PLAYER_2 };
private JButton[] fields;
private JPanel contentPanel;
public GameLogic(int size) { public GameLogic(int size) {
if (size < 3) { if (size < 3) {
@ -101,15 +104,15 @@ public class GameLogic {
} }
public JPanel generateGUI() { public JPanel generateGUI() {
JButton[] fields = new JButton[(int) Math.pow(this.board.length, 2)];
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new GridLayout(this.board.length, this.board.length));
this.fields = new JButton[(int) Math.pow(this.board.length, 2)];
this.contentPanel = new JPanel();
this.contentPanel.setLayout(new GridLayout(this.board.length, this.board.length));
for (int i = 0; i < fields.length; i++) {
fields[i] = new JButton();
contentPanel.add(fields[i]);
for (int i = 0; i < this.fields.length; i++) {
this.fields[i] = new JButton();
this.contentPanel.add(this.fields[i]);
} }
return contentPanel;
return this.contentPanel;
} }
} }
Loading…
Cancel
Save