Minsweeper game advice

I am currently in the process of making a java minesweeper game for school and have run into a problem. I have created an array of 64 buttons arranged in a grid layout. The problem i am having is getting the x and y co-ordinates of a particular button pressed and sending these co-ordinates to another class which contains a 2d array. any suggestions on how i can obtain the x and y position of the button pressed???
any help on this matter would be greatly appreciated



Once you know the click position you can use basic math to get the square hit. Then it’s object-oriented programming to give that info to other parts of the game. You could follow a MVC (Model View Controller) pattern.

Basically your controller (main part) will register as listening to your view (your button(s)).

Here is a similar game with source code included if it helps.

Leave a Reply

Your email address will not be published. Required fields are marked *