There can be two approach for your use case:
First Approach:
Like say I want to show the picture for 1000 seconds. So I will execute for loop till 1000 seconds; or if you want to run it infinitely then you can change the condition in for loop. Below code will execute the for loop after every 5 seconds delay.
int delayTimeInMiliSec;
for(int delayTime = 5 ; delayTime<=1000; delayTime = delayTime+5){
delayTimeInMiliSec = delayTime * 1000;
// here Call your method that shows pictures
Thread.sleep(delayTimeInMiliSec);
}
Second Approach:
- create a class extending TimerTask(available in java.util package). TimerTask is a abstract class.
- Write your code in public void run() method that you want to execute periodically.
Code sample:
import java.util.TimerTask;
// Create a class extends with TimerTask
public class ScheduledTask extends TimerTask {
// Add your task here
@Override
public void run() {
//show pictures code
}
}
import java.util.Timer;
public class SchedulerMain {
public static void main(String args[]) throws InterruptedException {
Timer time = new Timer(); // Instantiate Timer Object
ScheduledTask st = new ScheduledTask(); // Instantiate SheduledTask class
time.schedule(st, 0, 5000); // Create Repetitively task for every 5 secs
}
}