Im making an application that should be able to read files in a given directory and then display all image files in a fullscreen borderless window, it should also display text files, but i havent started on that part yet, so never mind the system.out part. So far ive made the JFrame fullscreen and borderless, and ive made an Arraylist containing the files i want shown. I then add a jpanel with the file in the constructor, this jpanel adds the picture to a jlabel and displays it, afterward i remove the jpanel and start over with the next picture.
What i need is a way to make the images fade in from a given color, and then fade out to that same color.
this is where i add the panels and remove them again
for (File f : files) {
String fileName = f.getName();
if (fileName.endsWith(".txt")) {
System.out.println("Txt");
System.out.println(fileName);
System.out.println("--");
} else if (fileName.endsWith(".png") || fileName.endsWith(".jpg") || fileName.endsWith("bmp")) {
AlbumPanel albumpan = new AlbumPanel(connect, f, this);
add(albumpan, BorderLayout.CENTER);
pack();
try {
Thread.sleep(current.getFormat().getPicLength()*1000);
} catch (InterruptedException ex) {
}
remove(albumpan);
}
}
And this is the JPanel
public class AlbumPanel extends JPanel {
BufferedImage image;
ImageIcon icon;
IConnect connect;
File pic;
JFrame presWin;
public AlbumPanel(IConnect connect, File pic, JFrame presWin) {
this.connect = connect;
this.pic = pic;
this.presWin = presWin;
this.setLayout(new GridBagLayout());
try {
image = ImageIO.read(pic);
} catch (Exception e) {
System.out.println(e);
}
image = resize(image, presWin.getWidth(), presWin.getHeight());
icon = new ImageIcon(image);
JLabel picLabel = new JLabel();
picLabel.setIcon(icon);
add(picLabel);
setVisible(true);
}
private BufferedImage resize(BufferedImage image, int width, int height) {
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TRANSLUCENT);
Graphics2D g2d = (Graphics2D) bi.createGraphics();
g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
g2d.drawImage(image, 0, 0, width, height, null);
g2d.dispose();
return bi;
}