I am trying to shuffle image from my folder image which I am able to do. what I have to pass the name of image but I don't want pass the name of image I just want to give the name of folder and all image should from there how can I do this
Here is my code
public class main1 extends javax.swing.JFrame {
private JLabel ecause = new JLabel();
private List<BufferedImage> list = new ArrayList<BufferedImage>();
private List<BufferedImage> shuffled;
private JLabel label = new JLabel();
private int width = 700;
private int height = 700;
private Timer timer = new Timer(4000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
update();
}
});
public main1() {
this.getContentPane().setBackground(new java.awt.Color(153, 153, 0));
this.setUndecorated(true);
ecause.setText(" eCause List");
ecause.setBounds(0, 1278, 496, 88);
ecause.setFont(new java.awt.Font("Times New Roman", 1, 40));
ecause.setBackground(new java.awt.Color(255, 153, 0));
ecause.setOpaque(true);
this.add(ecause);
initComponents();
try {
list.add(resizeImage(ImageIO.read(new File("images\\Picture2.png"))));
list.add(resizeImage(ImageIO.read(new File("images\\Picture3.png"))));
list.add(resizeImage(ImageIO.read(new File("images\\Picture4.png"))));
list.add(resizeImage(ImageIO.read(new File("images\\Picture5.png"))));
} catch (IOException e) {
e.printStackTrace();
}
shuffled = new ArrayList<BufferedImage>(list);
Collections.shuffle(shuffled);
timer.start();
}
private BufferedImage resizeImage(BufferedImage originalImage) throws IOException {
BufferedImage resizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, width, height, null);
g.dispose();
return resizedImage;
}
private void update() {
if (shuffled.isEmpty()) {
shuffled = new ArrayList<BufferedImage>(list);
Collections.shuffle(shuffled);
}
BufferedImage icon = shuffled.remove(0);
jLabel3.setIcon(new ImageIcon(icon));
}
}
How can I achieve my output?