public static void main(String args[]) throws InterruptedException, IOException
    {
    	long timegap = 0;
    	if(args.length == 1)
    		ImageSegFrame.saveFileDir = (args[0]) + "";
    	else
    		if(args.length == 2)
    		{
    			ImageSegFrame.saveFileDir = args[0] + "";
    			timegap = Long.parseLong(args[1]); 
    		}
    
    	new ActionRobot();
    	BufferedImage screenshot = null;
    	ImageSegFrame frame = null;
    	screenshot = ActionRobot.doScreenShot();
    	frame = new ImageSegFrame(" Screenshots ", screenshot, null);
    	List<BufferedImage> images = new LinkedList<BufferedImage>();
    	long time;   
    	long avg = 0;
    	while(true)
    	{
    		if(recordScreenshot){
    			time = System.nanoTime();
    			screenshot = ActionRobot.doScreenShot();
    			images.add(screenshot);
	    		Thread.sleep(timegap);
	    		avg += (System.nanoTime() - time);
    		} 
    		else
    		{
    			screenshot = ActionRobot.doScreenShot();
    		}
    		frame.refresh(screenshot);
    		if(saveAndExit)
    		{
    			saveFileDir += "_" + (avg/images.size()/1000000) + "\\";
    			File file = new File(ImageSegFrame.saveFileDir);
    	    	if(!file.exists())
    	    		file.mkdir();
    		  for (BufferedImage image : images)
    		  {
    			  String imgFilename = saveFileDir + String.format("img%04d.png", _saveCount ++);
    			  System.out.println("saving image to " + imgFilename);
      			  ImageIO.write(image, "png", new File(imgFilename));
    		  }
    		  System.exit(0);
    		}
    	}
    	
/*    	if(recordScreenshot)
    		for (BufferedImage image : images)
    		{
    			String imgFilename = saveFileDir + String.format("img%04d.png", _saveCount ++);
    			ImageIO.write(image, "png", new File(imgFilename));
    		}
    	*/
    
    
    }