I am trying to build a clock in javafx but the GUI crashes when I try using an infinite loop.
while (true) {
Date time = new Date();
// mins and hour are labels
if (time.getMinutes() < 10) {
mins.setText("0" + Integer.toString(time.getMinutes()));
} else {
mins.setText(Integer.toString(time.getMinutes()));
}
if (time.getHours() < 10) {
hour.setText(0 + Integer.toString(time.getHours()));
} else {
hour.setText(Integer.toString(time.getHours()));
}
}
I heard I can use something called a thread but I didn't really understand how to properly implement it.