I already wanted to make two games in java but I couldn't finish them because I had no idea how to design them well. I have several questions, all more or less, pointing to the same side:
1.How do I design the board well? Is it done in a one dimensional or bi(xy) array each with the corresponding sprite instances?
2.How do I make the "tiles" have a mouse listener? Until now that was my biggest problem (it occurred to me to see the mouse click x,yy compared to the x,y of each instance of the map...but I noticed that the machine was getting very hot due to so many for loops...something wrong)
There is not much difference between doing:
and this other
Performance wise, in this SOen answer, you can see that there is no substantial difference either.
This decision is more a matter of personal preference than a technical issue. I would use the first one, since it generates different bytecodes and it is not known if there may be specific optimizations in the future.
What I would do is a function that translates the screen coordinates to the map or board coordinates.
It's just a question of scale, if it's a chessboard the scale is 8 x 8, if it's a world with scroll and zoom, with a little math you calculate it, the point here is that the coordinates of the screen and the ones on the board are in different "domains", so you need a way to translate from one sense to the other (and vice versa for drawing).
With the coordinates of the board, it will be easy to find what is underneath.