I am trying to make a rubix cube timer for my friend. To start the timer you hold down space bar, and once you let go it starts. I am having a problem though, when I hold down the space bar the timer starts at whatever time it is. I want to be able to reset it to 0 but whenever I try to do that everything glitches out. Could anyone tell me how to fix it, or how to do this in a more efficient way? Thanks!

```
package dev.suns.rubix_timer;

import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Timer;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

public class RubixTimerMain extends JFrame {

private JPanel contentPane;
private JLabel labelTimer;
private Timer timer;

public RubixTimerMain() {
    createWindow();
}

public static void main(String[] args) {
    new RubixTimerMain();
}

private void createWindow() {

    // setUndecorated(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(Toolkit.getDefaultToolkit().getScreenSize());
    setLocationRelativeTo(null);
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    contentPane = new JPanel();

    contentPane.setBackground(new Color(201, 77, 83));
    contentPane.setLayout(null);
    setContentPane(contentPane);

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                startTimer();
            }
        }
    });

    JLabel lblMinimize = new JLabel("-");
    lblMinimize.setBounds(1835, -20, 16, 95);
    lblMinimize.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            setState(JFrame.ICONIFIED);
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            lblMinimize.setForeground(Color.BLACK);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            lblMinimize.setForeground(Color.WHITE);
        }
    });
    lblMinimize.setForeground(Color.WHITE);
    lblMinimize.setFont(new Font("Segoe UI", Font.PLAIN, 40));
    contentPane.add(lblMinimize);

    JLabel lblX = new JLabel("X");
    lblX.setBounds(1873, 0, 24, 54);
    lblX.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            System.exit(0);
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            lblX.setForeground(Color.BLACK);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            lblX.setForeground(Color.WHITE);
        }
    });

    lblX.setFont(new Font("Segoe UI", Font.PLAIN, 40));
    lblX.setHorizontalAlignment(SwingConstants.CENTER);
    lblX.setForeground(Color.WHITE);
    contentPane.add(lblX);

    labelTimer = new JLabel("0.0.0");
    labelTimer.setHorizontalAlignment(SwingConstants.CENTER);
    labelTimer.setFont(new Font("DINPro-Bold", Font.PLAIN, 200));
    labelTimer.setForeground(Color.WHITE);
    labelTimer.setBounds(371, 134, 1418, 653);
    contentPane.add(labelTimer);
    setVisible(true);
}

```

This is where I have the timer code. I have tried to reset cal to 0 in several different places but it is not working.

```
private void startTimer() {
    new Thread()
    {
        public void run()
        {
            while(true)
            {
            Calendar cal = new GregorianCalendar();
            int minutes = cal.get(Calendar.MINUTE);
            int seconds = cal.get(Calendar.SECOND);
            int milliseconds = cal.get(Calendar.MILLISECOND);
            labelTimer.setText(minutes + "." + seconds + "." + milliseconds);
            }
        }
    }.start();
}

```

}