我想在小程序里逐个显示所有图像, 但是它只显示下面所给出的文件夹的最后一张图像 。
public class ImageInSwingTest extends JApplet
{
String filePath="C:\Users\yogi\Pictures\pictures"; //all .png files more than 200 files
String files;
File folder=new File(filePath);
File[] listOfFiles;
Image m;
@Override
public void init()
{
listOfFiles=folder.listFiles();
for(int i=0;i<listOfFiles.length;i++)
{
if(listOfFiles[i].isFile())
{
files=listOfFiles[i].getName();
if(files.endsWith(".png"))
{
String filepath=listOfFiles[i].getAbsolutePath();
System.out.println(filepath);
try {
m = ImageIO.read(new File(filepath));
paint(ImageInSwingTest.this.getGraphics());
} catch (IOException ex) {
Logger.getLogger(ImageInSwingTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
public void paint(Graphics g)
{
g.drawImage(m, 0, 0, this);
}
}
so, please can any one tell me how can i display all images one by one.? Thanks.