I made a simple game or two with Java and I used Swing Timer to handle the main game loop. A timer allows you to set an ActionListener that will be started after the expiration of the provided delay . The intermediate delay will be obtained from your frame rate. The most basic use would look like this:
Timer timer = new Timer(delay, listener); timer.start();
This would set the initial and intermediate delays to the same value. You can also set different values ββfor them, if necessary:
Timer timer = new Timer(delay, listener); timer.setInitialDelay(0); timer.start();
In the above example, the listener will start as soon as possible after starting and with a delay between them.
source share