import java.io.File; import java.awt.CardLayout; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class ImageWindow extends JFrame { private CardLayout cards; private JPanel imagePanel; public ImageWindow() { this.setSize(1024, 1024); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); File resourcesDirectory = new File("../resources/"); if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) { File[] files = resourcesDirectory.listFiles(); if(files != null) { this.cards = new CardLayout(); this.imagePanel = new JPanel(); this.imagePanel.setLayout(this.cards); for(File file : files) { JLabel label = new JLabel(new ImageIcon(file.getPath())); label.setHorizontalAlignment(JLabel.CENTER); label.setVerticalAlignment(JLabel.CENTER); this.imagePanel.add(new JLabel(new ImageIcon(file.getPath())), file.getName()); } this.add(this.imagePanel); this.addMouseListener(new ClickSwapImageEvent(this)); this.addWindowListener(new WindowClosedEvent(this)); this.nextImage(); } } } public void nextImage() { this.cards.next(this.imagePanel); } public void lastImage() { this.cards.previous(this.imagePanel); } }