Professional Documents
Culture Documents
Galleryapp
Galleryapp
*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public GalleryAppGUI() {
super("Photo Gallery App");
this.photoList = new ArrayList<>();
// Layout setup
setLayout(new BorderLayout());
add(buttonPanel, BorderLayout.NORTH);
add(photoScrollPane, BorderLayout.CENTER);
// Event listeners
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addPhoto();
}
});
displayButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
displayPhotos();
}
});
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
deletePhoto();
}
});
if (returnValue == JFileChooser.APPROVE_OPTION) {
File[] selectedFiles = fileChooser.getSelectedFiles();
for (File selectedFile : selectedFiles) {
String filePath = selectedFile.getAbsolutePath();
photoList.add(filePath);
}
}
}
photoPanel.revalidate();
photoPanel.repaint();
}
if (option == JOptionPane.YES_OPTION) {
photoList.clear();
photoPanel.removeAll();
photoPanel.revalidate();
photoPanel.repaint();
}
}
}