I'm creating a program to ping many computer labs at once. On the home UI there there are images that are either red or green based on if all of the computers are pingable or not. When I call the pingAllLabs method it changes them to red or green correctly, but all at once at the end rather than as each is finished.
This stackOverflow answer is very similar but I can't/don't know how to implement it
Here is the code that does the pinging. In the Lab class it creates an arraylist of strings of the PC names that are broken.
@FXML
public void pingAllLabs() throws IOException{
for (int i = 0;i<list.listOfLabs.size();i++{
list.listOfLabs.get(i).printBroke(fileName);
updateImages(list.listOfLabs.get(i),i);
}
}
And here is the code that actually changes the images. It retrieves the arrayList of broken pc's from the lab that is sent to it and if the list is not empty it changes the image in an arraylist of images to red or if the list is empty it changes it to green.
@FXML
public void updateImages(Lab lab,int i){
Image red = new Image("RedComp.png");
Image green = new Image("GreenComp.png");
ArrayList<String> list = lab.getBrokenList();
if (!list.isEmpty()){
images.get(i).setImage(red);
System.out.println("Setting "+lab.getName()+" to red");
}
else{
System.out.println("Setting to green");
images.get(i).setImage(green);
}
}