public Ui(Timer timer) { this.timer = timer; Timer.setCALLBACK( (i) -> { try (PrintWriter printWriter = new PrintWriter(new FileWriter("storage.txt"))) { printWriter.println("start" + (System.currentTimeMillis() - (i * 1000))); } catch (IOException e) { e.printStackTrace(); } timeLabel.setText(String.valueOf(i)); }); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setMinimumSize(new Dimension(300, 100)); frame.setContentPane(contentPanel); contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.LINE_AXIS)); frame.add(startButton); frame.add(pauseButton); frame.add(stopButton); frame.add(timeLabel); startButton.addActionListener( (actionEvent) -> { Timer.start(); }); pauseButton.addActionListener( (actionEvent) -> { Timer.pause(); try (PrintWriter printWriter = new PrintWriter(new FileWriter("storage.txt"))) { printWriter.println("pause" + timer.curTime); } catch (IOException e) { e.printStackTrace(); } }); stopButton.addActionListener( (actionEvent) -> { Timer.stop(); try (PrintWriter printWriter = new PrintWriter(new FileWriter("storage.txt"))) { printWriter.println("stop" + timer.curTime); } catch (IOException e) { e.printStackTrace(); } }); }