@@ -149,6 +149,7 @@ private void startTimerTask() {
149149 // Pick whether we choose to subtract from session or break time.
150150 long sessionMinutes = 0 ;
151151 if (getState () == State .BOOTED || getState () == State .FOCUS ) {
152+ setState (State .FOCUS );
152153 sessionMinutes = getFocusMinutes ();
153154 }
154155 else if (getState () == State .BREAK ) {
@@ -164,7 +165,10 @@ public void run() {
164165 // If the timer is below zero, or it has been stopped, cancel the updates.
165166 if (systemTime - startTime > finalSessionMinutes * 60 * 1000 || isTimerStopped ()) {
166167 this .cancel ();
167- if (getState () == State .BOOTED || getState () == State .FOCUS ) {
168+ if (getState () == State .BOOTED ) {
169+ resetTimerAndMessage (Locale .GREET_MESSAGE );
170+ }
171+ else if (getState () == State .FOCUS ) {
168172 endFocusPeriod ();
169173 }
170174 else if (getState () == State .BREAK ) {
@@ -173,7 +177,7 @@ else if (getState() == State.BREAK) {
173177 }
174178 // Update the timer with the new remaining time.
175179 else {
176- setLabelTimer (Utils .convertRemainingMillisToMinutes (systemTime - startTime , getFocusMinutes () ));
180+ setLabelTimer (Utils .convertRemainingMillisToMinutes (systemTime - startTime , finalSessionMinutes ));
177181 }
178182 }
179183 }, 0 , 100 );
@@ -212,18 +216,28 @@ public void actionPerformed(ActionEvent e) {
212216
213217 helpMenu .add (aboutItem );
214218 helpMenu .add (usageItem );
219+
220+ JMenuItem resetItem = new JMenuItem ("Reset" );
221+ JMenu settingsMenu = new JMenu ("Settings" );
222+
223+ resetItem .addActionListener (new ActionListener () {
224+ @ Override
225+ public void actionPerformed (ActionEvent e ) {
226+ setState (State .BOOTED );
227+ setTimerStopped (true );
228+
229+ JOptionPane .showMessageDialog (null , Locale .RESET_MESSAGE );
230+ }
231+ });
232+
233+ settingsMenu .add (resetItem );
234+
235+ menubar .add (settingsMenu );
215236 menubar .add (helpMenu );
216237 frame .setJMenuBar (menubar );
217238 }
218239
219- public App () {
220- this .frame = new JFrame ();
221- initFrame (this .frame );
222-
223- this .menubar = new JMenuBar ();
224- initMenuBar (this .menubar , this .frame );
225-
226- // Start button logic
240+ private void initButtons (JButton buttonStart , JButton buttonStop ) {
227241 buttonStart .addActionListener (new ActionListener () {
228242 @ Override
229243 public void actionPerformed (ActionEvent e ) {
@@ -254,6 +268,17 @@ public void actionPerformed(ActionEvent e) {
254268 });
255269 }
256270
271+ public App () {
272+ this .frame = new JFrame ();
273+ initFrame (this .frame );
274+
275+ this .menubar = new JMenuBar ();
276+ initMenuBar (this .menubar , this .frame );
277+
278+ // Start button logic
279+ initButtons (this .buttonStart , this .buttonStop );
280+ }
281+
257282 public static void main (String [] args ) {
258283 new App ();
259284 }
0 commit comments