I am trying to take continuous pictures of small window of my screen and create a continuos motion picture sort of thing and display it on the java panel .
For this i am taking snapshots of the screen window by using "Robot" class .
but the panel is only showing the last picture it took. I dont know what to do.............
pls help.............
this is the code i used.............
import java.awt.image.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.geom.*;
import javax.imageio.ImageIO;
public class ScreenVideo
{
public static void main(String args[]) throws Exception
{
ScreenFrame frame=new ScreenFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class ScreenFrame extends JFrame
{
public ScreenFrame() throws Exception
{
setTitle("testing");
setSize(500,500);
ScreenPanel panel=new ScreenPanel();
add(panel);
}
}
class ScreenPanel extends JPanel
{
public BufferedImage img;
public ScreenPanel() throws Exception
{
takeShots();
}
public void takeShots() throws Exception
{
long time=1000L;
Rectangle rec=new Rectangle(100,100,300,300);
Robot robot=new Robot();
int i=0;
while(i!=100)
{
System.out.println("running in the loop with counter#"+i);
img = robot.createScreenCapture(rec);
Thread.sleep(time);
repaint();
i++;
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
g2.drawImage(img,0,0,this);
}
}