Hi, I'm having trouble getting my timer to be continuously updating. Once I click the button to start the timer it just shows 0. However, it shows the correct time after you finish.
public long getElapsedTime() { long elapsed; if (running) { elapsed = (System.currentTimeMillis() - startTime); } else { elapsed = (stopTime - startTime); } return elapsed; } GameClient2 s = new GameClient2(); if(e.getSource()==b4) { s.start(); String get = Long.toString(s.getElapsedTime()); textField2.setText(get); //this just updates it once... } if(e.getSource()==b1) { s.stop(); double et = s.getElapsedTime(); double sec = et/1000; JOptionPane.showMessageDialog(null, "You got it! Your elapsed time in seconds was: "+sec,"Correct!",JOptionPane.INFORMATION_MESSAGE); System.exit(0); }
So I know that I'm only updating it once, but I can think of no other way to do this.