Files
BUT2/DEV/DEV3.1/TP02/Part2/ImageWindow.java

56 lines
1.6 KiB
Java
Raw Normal View History

2025-09-26 11:16:47 +02:00
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);
}
}