I am working on a Connect Four game for a school Java project. I've got the 'how' of the JLayeredPane, and it is working as expected, but I'm not quite getting the 'why' behind a certain concept.
Here is my understanding:
JLayeredPane is a container, similar to JPanel, that allows you to specify depth and position for each component. Depth is an Integer, with 0 being the bottom layer and n-1 being the top layer, with n being the number of components. Position is an int (yes, one uses the Integer wrapper class and one is just a primitive!) that specifies a component's postion within the layer, with 0 being the topmost layer, -1 being the bottom-most layer, and positive ints in between, the lower the number the higher the position. So, four components in a single layer could be ordered into position 0, 1, 2, -1 from topmost to bottom-most.
My question is, what's the need to have both concepts?
For instance, I have created three JLabels with images: a frontBoard, a backBoard, and a piece. The piece sometimes goes in front of the frontBoard and sometimes goes between the frontBoard and the backBoard. Let's examine the second example.
I can get the same effect through either of these means:
1) I can set the backBoard to layer 0, position 0; the piece to layer 1, position 0; and the frontBoard to layer 2, position 0
or
2) I can set the backBoard to layer 0, position -1; the piece to layer 0, position 1; and the frontBoard to layer 0, position 0
I have tested both of these ways, and I can't find a functional difference between the two methods.
Can anyone shed any light on this mystery for me?