I am new to using the Timer class, and so am trying to experiment with it before incorporating it into my project. I am wondering why this program does not terminate when the count reaches 5. The program keeps running even though the condition for the while loop is not satisfied.
package Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
public class demo {
private static int count;
public static void main(String[] args) {
ActionListener executeThis = new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
System.out.println("Hello");
count++;
}
};
Timer timer = new Timer(500, executeThis);
timer.setInitialDelay(1000);
timer.start();
while(count < 5){
}
}
}