import javax.swing.*;
import java.awt.*;

    // Display the images within their own JInternalFrame
    // in a JDesktopPane.
class SwingLayerFrame3 extends JFrame {
    public SwingLayerFrame3(String[] images) {
        final int width = 450, height = 300;
        setSize(width,height);
        final Container contents = getContentPane();

        // Place a JDesktopPane within the frame to manage the
        // layering.
        contents.add(getPane(),"Center");

        setupImages(images);

        JPanel buttonPanel = new JPanel();
        buttonPanel.add(new QuitJButton());
        contents.add(buttonPanel,"South");
    }

        // Place a component holding each image into a separate
        // JInternalFrame in the desktop pane.
    protected void setupImages(String[] images){
        final Container contents = getContentPane();
        final JDesktopPane desktop = getPane();
        // Where to place the first internal frame.
        final int initialX = 0, initialY = 0;
        // Where to locate each internal frame.
        Point initialLocation = new Point(initialX,initialY);

        final int numImages = images.length;
        for(int i = 0; i < numImages; i++){
            final JComponent image = new JLabel(new ImageIcon(images[i]));
            // Set the image's preferred size.
            image.setSize(image.getPreferredSize());

            // Create an internal frame to hold the image.
            JInternalFrame imageFrame = new JInternalFrame();

            // Add the image to the frame's content pane.
            imageFrame.getContentPane().add(image);
            imageFrame.setLocation(initialLocation);
            imageFrame.setResizable(true);
            imageFrame.setIconifiable(true);
            imageFrame.setTitle(images[i]);

            imageFrame.pack();

            // Add all frames to the same layer.
            desktop.add(imageFrame);

            // Place the next directly alongside.
            initialLocation.x += imageFrame.getSize().width;
        }
    }

    protected JDesktopPane getPane(){
        return desktop;
    }

    // The desktop in which the labels will be stored.
    private final JDesktopPane desktop = new JDesktopPane();
}
