I'm doing a job, and I wanted to know in a simple way how I solve this, I'm doing a simple program in it's almost a game, basically you push a button, the progress bar starts to grow, and adds 1 point to a Label. but when I put it to work, it does both at the same time and the point goes before the progress bar if it finishes, could anyone help me?
Controller method:
@FXML Label lb$;
int dinheiro = 0;
@FXML
public void botão() {
BarraDeProgresso b = new BarraDeProgresso(100, 90, barra);
new Thread(b).start();
dinheiro++;
lb$.setText(String.valueOf(dinheiro));
}
Class ProgressBar :
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.scene.control.ProgressBar;
public class BarraDeProgresso extends Task<Void>{
private int qt;
private int tempo;
private ProgressBar barra;
public BarraDeProgresso(int qt, int tempo, ProgressBar barra) {
this.qt = qt;
this.tempo = tempo;
this.barra = barra;
barra.setProgress(0);
}
public void inicia() {
double incremento = 1.0/qt;
for(int i=0; i<qt; i++){
try {
Thread.sleep(tempo);
barra.setProgress(barra.getProgress()+incremento);
} catch (Exception e) {
e.printStackTrace();
}
}
}
//gets e sets implementados