I have a java swing gui program and when I click a toggle button a timer begins but I want to be able to click the same button and the timer stops and right now it won't let me click on it again. This is in my timer class
public void runningClock(){
isPaused = false;
while(!isPaused){
incrementTime();
System.out.println("Timer Current Time " + getTime());
time.setText(""+ getTime());
try{Thread.sleep(1000);} catch(Exception e){}
}
}
public void pausedClock(){
isPaused=true;
System.out.println("Timer Current Time " + getTime());
time.setText(""+ getTime());
try{Thread.sleep(1000);} catch(Exception e){}
}
and this is in my main class
private void btnRunActionPerformed(java.awt.event.ActionEvent evt) {
if(btnRun.getText().equals("Run")){
System.out.println("Run Button Clicked");
btnRun.setText("Pause");
test.runningClock();
}
else if(btnRun.getText().equals("Pause")){
System.out.println("Pause Button Clicked");
btnRun.setText("Run");
test.pausedClock();
}
}