I'm currently programming in Java. When the user presses the program's start button, I'd like a loop to start. But then I'd like the user to have the ability to stop the loop with a stop button:
public class Program {
private boolean active;
// MVC stuff...
private class StartListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
// Do stuff...
active = true;
hotelCalifornia();
}
}
private class StopListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
// Do stuff...
active = false;
}
}
public void hotelCalifornia() {
while (this.active) {
// The program never leaves!
}
}
}
But once the loop is started, the program only performs the actions of the loop. Is there a way around this? Is there a better way to accomplish my goal?
Thanks!