I try to get a score count on the UI, to be refreshed several times per second. The refresh should not prevent the other elements of the UI from working (Buttons should remain clickable etc.)
I read the doc on the EDT
and tried to add a method called from the constructor of the Form
:
private void loopScore() {
Display.getInstance().callSerially(
() -> {
while (true) {
try {
MyApplication.score = MyApplication.score + 1;
this.gui_Score.setText(String.valueOf(MyApplication.score));
Thread.sleep(100);
} catch (InterruptedException ex) {
//do something
}
}
});
}
But this does not update gui_Score
and it blocks the rest of the UI. Help?