Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Mahjong game java project [GUI]

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:
  • 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. 🎉
(Dec 3, 2018 06:32 AM)georgeziozas Wrote:  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:
  • 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. 🎉
why do you need the x1, x2, ect why don't you store these buttons in a hashmap and use key value pairs to check which one is clicked by the user
(Dec 3, 2018 11:10 AM)Master3clipse Wrote:  why do you need the x1, x2, ect why don't you store these buttons in a hashmap and use key value pairs to check which one is clicked by the user

it was a test thats why .
Thats how i procceded at the end.
is anyone able to come to skype to solve some major problems on this code ? \
thanks.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by imagedosheaderAug 14, 2023 07:08 AM 2 159 Aug 14, 2023 07:08 AM
Last Post: imagedosheader
[Java] by Monostable555Oct 24, 2016 07:44 AM 9 282 Oct 24, 2016 07:44 AM
Last Post: Captain Steve Rogers
[Python] by PaddingtionDec 19, 2015 03:56 AM 1 114 Dec 19, 2015 03:56 AM
Last Post: NON-