I am making a program to run minecraft and I have a problem - i need to stop the task when user clicks the button.
Here is my code:
public void onStart(ActionEvent actionEvent) {
Task<Void> task = new Task<Void>() {
@Override
protected Void call() {
RunMinecraft.runMinecraft(null);
return null;
}
};
new Thread(task).start();
}
RunMinecraft.class:
public class RunMinecraft {
public static void runMinecraft(String server) {
//Here processes:
//Auth user
//Check all files
//Download all needed files
//Run Game
}
}
I also tried to create a new boolean variable and check it in runMinecraft method after each process and if this (boolean == false), I stopped the method. But this case is not good.
I also tried this code: JavaFX - Cancel Task doesn't work But my task didn't stop.
Thank you in advance.