public class Window extends JFrame {
private ArrayList<imgObj> allImages;
private JLabel[] labels;
private JPanel[] panels; //<-- contains the labels.
private JLayeredPane aLPane = new JLayeredPane() ; //<-- contains the panel.
public Window(){
super("title");
setLayout(new BorderLayout());
add(aLPane, BorderLayout.CENTER);
aLPane.setBounds(0,0,800,600);
LoadImages();
labels = new JLabel[allImages.size()];
panels = new JPanel[allImages.size()];
//loop through allImages, and give all images a label, and adds the label to the window.
int counter = 0;
for(imgObj i : allImages){
labels[counter] = new JLabel(i.getImg());
labels[counter].setOpaque(true);
labels[counter].setBackground(Color.BLUE);
labels[counter].setBounds(i.getPosx(), i.getPosy(), i.getImg().getIconWidth(),i.getImg().getIconHeight());
panels[counter].add(labels[counter]);
panels[counter].setOpaque(true);
panels[counter].setBounds(0, 0, 800, 600);
panels[counter].setBackground(Color.BLACK);
System.out.printf("%s was added to window, as pos (%d ; %d)\n", i.getName(), i.getPosx(), i.getPosy());
counter++;
aLPane.add(panels[counter], new Integer(i.getLayer()), 0);
}
}
}