want to chage display image after 2 second
hiin my program i am capturing the screen and showing it in to the jframe and after 2 second delay i am capturing again and want to display that new image in same jframe by following program but i am unable to do so
please help me out
package javaapplication1;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* @author Administrator
*/
publicclass Main{
/** Creates a new instance of Main */
public Main(){
}
/**
* @param args the command line arguments
*/
publicstaticvoid main(String[] args)
// TODO code application logic here
throws
AWTException, IOException{
// capture the whole screen
int i=0;
//BufferedImage screencapture = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );
JFrame frame =new JFrame();
while(i!=6)
{
BufferedImage image =new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JLabel(new ImageIcon(image)));
frame.pack();
frame.setVisible(true);
try{
Thread.sleep(2000);
}
catch(InterruptedException e){}
frame.setVisible(false);
//File file = new File(i+"screencapture.jpg");
// ImageIO.write(image, "jpg", file);
i++;
// Save as PNG
// File file = new File("screencapture.png");
// ImageIO.write(screencapture, "png", file);
}
//System.exit(0) ;
}
}

