Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.


+30 votes

Hi everyone,

I talked to Stonedahl about this yesterday, and he said it was interesting and that I should post it here. Our idea is that in manual tracking, every time you place a dot or circle marking the position of a chick, the video will automatically move forward by one time increment (1 second for us currently). However, we added in a time delay of half a second before the displayed frame updates so that the user can see where they placed the dot. Then, if they think it was placed badly, there's a redo button available that will reverse the time increment and show that previous frame with the dot placed.

The trick to making it work was not to use Thread.sleep() like we learned in CSC212 because JavaFX runs its update in a weird way chronologically where even if the placing the dot appears to be called first, the entire thread gets put to sleep before the dot is drawn and it never gets displayed before the displayed frame is updated. Instead, every time that mouse click occurs, a scheduled timer is created. Inside of that, we create a TimerTask object. Inside of that, we create and simultaneously call a run method that calls increment() where increment() is our method to update the displayed frame. I don't think I can post the full code here, so sorry if that's not clear, but I can probably show it to you in person if you're interested.

asked in CSC285_Fall2018 by (479 points)

1 Answer

+15 votes

While I agree you shouldn't post your whole .java file, but you certainly can post the short snippet of code that schedules some code to run 500 ms later. Here -- I'll do it for you:

new java.util.Timer().schedule(
    new java.util.TimerTask() {
        public void run() {
            Platform.runLater(() -> someMethodToRunLater());
    500);   // the delay time in milliseconds
answered by (3.4k points)