|
|
@ -6,17 +6,24 @@ import javax.swing.JPanel; |
|
|
|
|
|
|
|
public class MinesweeperGame extends JPanel { |
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
private static final int WIDTH = 600, HEIGTH = 600; |
|
|
|
private static final int CELLSIZE = 40; |
|
|
|
private int playfieldSize; |
|
|
|
|
|
|
|
public MinesweeperGame(int _playfieldSize) { |
|
|
|
this.setSize(600, 600); |
|
|
|
this.setSize(WIDTH, HEIGTH); |
|
|
|
playfieldSize = _playfieldSize; |
|
|
|
setLayout(null); |
|
|
|
initPlayfield(_playfieldSize); |
|
|
|
|
|
|
|
initPlayfield(); |
|
|
|
} |
|
|
|
|
|
|
|
private void initPlayfield(int _playfieldSize) { |
|
|
|
for (int i = 0; i < _playfieldSize; i++) { |
|
|
|
for (int j = 0; j < _playfieldSize; j++) { |
|
|
|
private void initPlayfield() { |
|
|
|
for (int i = 0; i < playfieldSize; i++) { |
|
|
|
for (int j = 0; j < playfieldSize; j++) { |
|
|
|
JButton b = new JButton(); |
|
|
|
b.setBounds(j * 40, i * 40, 40, 40); |
|
|
|
b.setBounds(j * CELLSIZE, i * CELLSIZE, CELLSIZE, CELLSIZE); |
|
|
|
add(b); |
|
|
|
} |
|
|
|
} |
|
|
@ -27,7 +34,7 @@ public class MinesweeperGame extends JPanel { |
|
|
|
MinesweeperGame ttt = new MinesweeperGame(8); |
|
|
|
|
|
|
|
f.add(ttt); |
|
|
|
f.setSize(600, 600); |
|
|
|
f.setSize(WIDTH, HEIGTH); |
|
|
|
f.setLayout(null); |
|
|
|
f.setVisible(true); |
|
|
|
|
|
|
|