timer
setup Form
import Packages
- goes at very top of Source code lines 1-4 so either get rid of the comments that are there or move them down
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.Timer;
public Variables
- goes just inside the whole public class jFrame declaration, but still appears before the constructor. FYI the constructor is the public procedure that has the initComponents() method in it that loads when the program starts... hence the word 'constructor'
public int seconds = 0;
public Timer myWatch = null;
jFrame Constructor
- put this on the next line available directly underneath the line of code that has initComponents() on it:
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;