I already have the code for start button - already made a reference to the JLabels. But I am in trouble coding for the pause/resume and stop. I also searched for the "schedule" function but I don't know how to implement it. Please help.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.pingol.thread;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
public class Timer implements Runnable {
JLabel miliseconds;
JLabel seconds;
JLabel minute;
public Timer(JLabel miliseconds, JLabel seconds, JLabel minute){
this.miliseconds = miliseconds;
this.seconds = seconds;
this.minute = minute;
}
@Override
public void run() {
for (int i = 0; i < 60; i++){
this.minute.setText(Integer.toString(i));
for (int j = 0; j < 60; j++) {
this.seconds.setText(Integer.toString(j));
for (int k = 0; k < 60; k++) {
this.miliseconds.setText(Integer.toString(k));
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Logger.getLogger(Timer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
}
/*
FRAME (s**strong text**tart):
private void startActionPerformed(java.awt.event.ActionEvent evt) {
Timer timer = new Timer(miliseconds,seconds,minutes);
Thread th = new Thread(timer);
th.start();
}
*/