-1
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 which it’s almost a game, basically you push a button, the progress bar starts to grow, and adds 1 point on a label. only when I put it to work, it performs both at the same time and the point goes before the progress bar concludes, someone could help me?
Method in Controller:
@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 Barradeprogresso:
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
Good afternoon Listen, I suggest you post what you have already managed to do, take a look at this link on How to create a Minimum, Complete and Verifiable example
– Alvaro Alves
Stick to certain patterns about questions as it’s hard to know how to help if you don’t give us a direction, and welcome to the community
– Alvaro Alves
Put in the codes, improved?
– Otavio de Oliveira Comeli