External Exam Download Resources Web Applications Games Recycle Bin

timer



setup Form
timer jFrame Form
import Packages
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.Timer;

public Variables
public int seconds = 0;
public Timer myWatch = null;

jFrame Constructor
ActionListener countSeconds = (ActionEvent meh) -> {
    //--------DAY TIME:
    Date rightNow = new Date();
    lblTimeOfDay.setText(rightNow.toString());
    
    //--------STOP WATCH TIME: 
    seconds++;
    lblStopWatchTime.setText(Integer.toString(seconds));
};
 
myWatch = new Timer(1000, countSeconds);

btnStart
myWatch.start();

btnStop
myWatch.stop();

btnReset
seconds = 0;