I'm stuck at this problem. I have to visualize Selection Sort Algorithm in Java, I decided to use JavaFX for UI. In my code, I have array of numbers and array of buttons. I used buttons to see the output of number array step by step. But I only get output result when all the loop process ends. I want to do it like this example: https://algorithm-visualizer.org/brute-force/selection-sort
I searched about it and know that I have to use threads but I couldn't handle it. Can you please help me?
@FXML
private void btnTik(ActionEvent event){
    Action action = new Action();
    new Thread(){
        public void run(){
    for(int i = 0 ; i < nums.length ; i++){
            min = i;
            for(int j = i+1 ; j < nums.length ; j++){
                if(nums[j] < nums[min]){
                    min = j;
                    btn[i].setText(Integer.toString(nums[i]));
                    action.sleep(200); //Thead.sleep(200)
                }
                btn[i].setText(Integer.toString(nums[i]));
                action.sleep(200);
            }
            nums = action.Degistir(nums, i, min);
                btn[i].setText(Integer.toString(nums[i]));
                action.sleep(200);
            System.out.println(nums[i]+" ");
    }
        }
    }.run();
}