Here I give you a rough recipe so that you can build one for
yourself easily.

1) three arrays ( one int [x][y] for data, one JButton [x][y] as the game pad, another int[x][y] array to keep track of the correct flags. )

2) random number generator to set an int data[i][j] to a certain value (that value will represent an existence of mine) to
loop for desired amount(amount of mines you want), but check not to assign to the
same box again. Otherwise, there may be less mines then the
desired amount.

3) after these, count the mines around a box with some
loops, but the sides need special attention( arrayOutof bound error)

4) action event handling (left mouse click) if arrayInt[i]
[j] == 1 boom hits the mine, start a new game. else
display the count as the text of the box using a recurvise method to reveal the near boxes if they are clear.

5)our first data[i][j] we know where the mine is.
The other int array then keeps track of where the question
marks are. Thus with
-Mouseclick evet , right click, when clicked, set this new
arrays specific element to specific value if the flags position is right.

6) then its more easy to check whether the mines and
question marks are on the same box. Count the question marks to determine whether puzzle is solved.

You may implement other optional things later like a flag counter, a time counter as you wish.