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) ;

}

}

[3751 byte] By [bhavin123400a] at [2007-11-27 5:58:23]
# 1

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.Dimension;

import java.awt.Graphics;

import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JLabel;

public class CatchAndShow {

private void nextStep(final JFrame frame, final JLabel label)

throws AWTException, IOException {

new Thread(new Runnable() {

public void run() {

try {

Thread.sleep(2000);

} catch(InterruptedException e) {

System.out.println("interrupted");

}

frame.dispose();

BufferedImage image = getScreenShot();

save(image, "png");

label.setIcon(new ImageIcon(image));

frame.validate();

frame.setVisible(true);

}

}).start();

}

private BufferedImage getScreenShot() {

// capture the whole screen

Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

BufferedImage image = null;

try {

image = new Robot().createScreenCapture(new Rectangle(d));

} catch(AWTException e) {

System.out.println("AWT error: " + e.getMessage());

}

return image;

}

private static void save(BufferedImage image, String ext) {

File file = new File("screencapture." + ext);

try {

ImageIO.write(image, ext, file);

} catch(IOException e) {

System.out.println("IO error: " + e.getMessage());

}

}

public static void main(String[] args) throws AWTException, IOException {

CatchAndShow app = new CatchAndShow();

BufferedImage image = app.getScreenShot();

app.save(image, "jpg");

JLabel label = new JLabel(new ImageIcon(image));

JFrame frame = new JFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.add(label);

frame.pack();

frame.setVisible(true);

app.nextStep(frame, label);

}

}

crwooda at 2007-7-12 16:32:57 > top of Java-index,Security,Cryptography...