I was trying to make a board game in java and i am stuck with the following problem.
I want to create a object that can be painted in the jpanel. Let's name this object Board. This board i want it to be a composite object of other boards. Hence when i call the (let's call it) paint() method of the board , in order to be correctly painted it will have to call paint it self and also call the paint() methods of its sub-boards etc. I know this is like an already implemented behavior (someone could say.. just make a Jpanel in a Jpanel) but the difference is that for the board object i want to be able to drag/ drop it anywhere in the Jpanel. Plus, the Jpanel may contain many boards which could be dragged/dropped anywhere in it (the can also overlap). So this kind of behavior restrict me from using Java swing components because they all use layouts which is not what i want.
Finally when i add a board object to a board the coords i use want to be relative to the parent board and not to the Jpanel's. (i.e when i add a board B to the board A, and i want to add the board B to (x,y)=(10,10) , these coords are relative to the location of A )
Is this any way to do it? I 'm not looking for complete example, just for general ideas (preferable clean!)
PS . i have implemented something that almost works. The problem in my implementation is that Graphics g , class Board uses to be painted is taken from the JPanel, and the x,y coords are relative to the JPanel for all the Boards (and not the the parent board in case the board is added to a parent board and not directly to JPanel).
i don't know if this is fusible but i am imaging that the leaf board is acutally painting it self with starting coords (0,0) which somehow in the JPanel are traslated to (x,y) depending on the actual location in the Jpanel of the board.
Thank you!