I am trying to have my program break out of a while loop when a button on the gui is pressed.
I have a thread which launches the GUI thread and the waits until an apply button is pressed. Here is the code:
public void run() {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
// Wait until apply button clicked and set team
while(true) {
applyClicked = gui.getApplyClicked();
if (applyClicked == true) {
teamYellow = gui.getTeam();
break;
}
}
However even when I click apply and the applyClicked becomes true within the GUI it does not execute that if statement.
However if I add a print line underneath the while true it works ok.
I also debugged it running line by line and the variables set correctly and it works.
Why doesn't this work when I don't have a println? Is it something to do with threads?
Thanks