Hello pals ,
So, i am working on a small project , trying to recreate a mahjong project with a GUI in java .
So far i have the basic implementation of the main logic of the game figured out but i am getting really confused when its time for the GUI development .
Here is my code's main concepts:
So, i am working on a small project , trying to recreate a mahjong project with a GUI in java .
So far i have the basic implementation of the main logic of the game figured out but i am getting really confused when its time for the GUI development .
Here is my code's main concepts:
- I have an abstract class Tiles which contains 2 basic methods isFree(taking the x and y position of the tile in the board) and isValid(checking 2 tiles if they are valid to be deleted)
- I have 5 type of Tiles , circles,baboo etc , each one of them implements the isvalid fucntion differently cause there are different rules for each of them on 'what they need to be deleted'
- I have a class board where i create a List<List<Tiles>> and i save inside all the Tiles objects of the game. The board has 54 elements and have dynamically created it cause there is not specific size to the rows. for example one row has 9 elements when last row may have 3.
- There is also a player class , A coordinates class (i keep the x,y of each object on the board)
- The board class has also a function decideToDelete(int x1,y1,x2,y2) takes as paramateres the spot of the first tile and the spot of the second and checks if it is valid to delete at last.
If you need more clarification on my code happy to reply.
Now here is the main problem im facing ,
I have created on the GUI class an array of JButtons , im trying to create a class which extends the Jbutton so i can save the info of the tile object inside the button so i can use it at the action listener.
The problem is how i am gonna get the x1,y1,x2,y2 of the 2 buttons that the user clicks so i can test them with my function?
The user has the board in front of him and must choose 2 tiles and if the tiles are consistent with the rules they must be deleted otherwise choose another pair.
how am i gonna achieve this, im really confused.
I thought about saving the buttons that the user clicked in a temp array and use the last 2 entries of it but it doesnt seem so OP programming nor good practice, correct me if am wrong .
I cant really find a solution to this on numerous stackoverflow questions or in web generally , maybe i need fundamental changes to the OP project structure?
Id found your help really usefull . Thanks in advance guys. 🎉

