package Minesweeper; import javax.swing.JButton; import javax.swing.JFrame; 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(WIDTH, HEIGTH); playfieldSize = _playfieldSize; setLayout(null); initPlayfield(); } private void initPlayfield() { for (int i = 0; i < playfieldSize; i++) { for (int j = 0; j < playfieldSize; j++) { JButton b = new JButton(); b.setBounds(j * CELLSIZE, i * CELLSIZE, CELLSIZE, CELLSIZE); add(b); } } } public static void main(String[] args) { JFrame f = new JFrame(); MinesweeperGame ttt = new MinesweeperGame(8); f.add(ttt); f.setSize(WIDTH, HEIGTH); f.setLayout(null); f.setVisible(true); } }