I am working on a Connect Four game for a Java school project. I have a βhowβ to JLayeredPane, and it works as expected, but I donβt quite understand the βwhyβ behind a certain concept.
Here is my understanding:
JLayeredPane is a container similar to JPanel, which allows you to specify the depth and position for each component. Depth is an integer, with 0 being the bottom layer, n-1 being the top layer, n the number of components. A position is an int (yes, one uses the Integer wrapper class, and the other uses a primitive!), Which indicates the component position inside the layer, with 0 being the topmost layer, -1 is the lowest layer and positive ints in between, the lower the number , the higher the position. Thus, four components in one layer can be ordered to the position 0, 1, 2, -1 from the highest to the lowest.
My question is that you need to have both concepts?
For example, I created three JLabels with images: frontBoard, backBoard and part. A piece sometimes goes in front of the frontBoard and sometimes goes between the frontBoard and the backBoard. Consider the second example.
I can get the same effect in one of the following ways:
1) I can set the backBoard to level 0, position 0; piece to layer 1, position 0; and frontBoard to level 2, position 0
or
2) I can set the backBoard to level 0, position -1; part to layer 0, position 1; and frontBoard to level 0, position 0
I tested both of these methods, and I cannot find the functional difference between the two methods.
Can anyone shed light on this mystery for me?