Search code examples
javaswing

Execute for loop every 20ms


I would like to execute a for loop that looks like this:

        int incAmt = 0;
        for (int i = 0; i < Double.parseDouble(arguments[0]); i += 0.9) {
            // Wait 20ms
            // do stuff
            // do stuff
            incAmt += 0.9;
        }

I can't sleep the main thread and I cant use TimeUnit wait function.. I am lost :\


Solution

  • yeah.. its in a gui

    For Swing, I'd recommend using a Swing Timer