Results 1 to 3 of 3
  1. #1
    Ericyue is offline Member
    Join Date
    Mar 2012
    Rep Power

    Exclamation time schedule rate rpoblem


    i have a program which should will print screen every 0.1s but when i compile and run, it print screen 2seconds 1 times but not print once/0.1seconds . below is my code

    import java.awt.Toolkit;
    import java.util.Timer;
    import java.util.TimerTask;

    import java.awt.image.BufferedImage;
    import java.awt.Rectangle;
    import java.awt.Dimension;
    import java.awt.Robot;
    import javax.imageio.ImageIO;

    * Schedule a task that executes once every second.

    public class Main {
    Toolkit toolkit;

    Timer timer;

    public Main() {
    toolkit = Toolkit.getDefaultToolkit();
    timer = new Timer();
    timer.scheduleAtFixedRate(new RemindTask(), 0, //initial delay
    100); //execute the code 1 seconds 1 time

    class RemindTask extends TimerTask {
    public void run() {

    try {
    Toolkit tool = Toolkit.getDefaultToolkit();

    Dimension d = tool.getScreenSize();
    Rectangle rect = new Rectangle(1024,768);
    Robot robot = new Robot();

    File f = new File("screenshot.jpg");
    BufferedImage img = robot.createScreenCapture(rect);

    } catch(Exception e){}

    }//close public void run
    }//close class Reminder

    public static void main(String args[]) {
    new Main();
    }//close public void main
    }//close class main

    is anyone what is the error/bug there that make the time schedule works incorrectly ?

    thanks in advance for the reply

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Bali, Indonesia
    Rep Power

    Default Re: time schedule rate rpoblem

    I think it is because you have a two seconds delay in you method.

    Java Code:
    Thread.sleep(2000); // two seconds

  3. #3
    Ericyue is offline Member
    Join Date
    Mar 2012
    Rep Power

    Default Re: time schedule rate rpoblem

    thanks so much . so i neglect that part .. very thanks for your help ..

Similar Threads

  1. comparing times/schedule algorithm
    By s3ib in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2011, 04:05 PM
  2. Calendar application to schedule vacations
    By tirwit in forum New To Java
    Replies: 8
    Last Post: 09-16-2010, 05:44 PM
  3. Programming NFL Schedule
    By PhilArmstrong in forum New To Java
    Replies: 0
    Last Post: 03-04-2010, 02:52 PM
  4. Java Schedule program
    By jaysyshaw in forum New To Java
    Replies: 0
    Last Post: 01-13-2010, 12:07 AM
  5. How to schedule a job in java
    By Malathi in forum Web Frameworks
    Replies: 4
    Last Post: 03-27-2009, 10:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts