How do I add a delay between 2 functions? I want one function to execute and after some delay another function to execute.
For example in the below code when AI vs CPU is chosen I want the outputs to be delayed....TimeUnit.SECONDS()
delays the whole process not each function call ..
So how can I add delay after each function call of CPU and AI in the following code:
public void actionPerformed(ActionEvent e) {
option = 3;
ai.setBackground(Color.WHITE);
int q = (int) (Math.random() * 2);
//System.out.println(" I have been called " + q);
if (q == 1) {
System.out.println(" I am inside " + q);
text1.setText(" AI starts ");
AI(1);
CPU(0);
AI(1);
CPU(0);
AI(1);
CPU(0);
AI(1);
CPU(0);
} else {
// System.out.println(" I have been inside " + q);
text1.setText(" CPU starts ");
CPU(1);
AI(0);
CPU(1);
AI(0);
CPU(1);
AI(0);
CPU(1);
AI(0);
}
}
});
EDIT: this is actually a tic tac toe game in which the Computer plays against the AI ....so as the output would be quick ...I want each step to be called and a delay to be there so that each move is visible.