public void startScan(String mode) {
   pathfindStart = System.currentTimeMillis();
   if (!gridSet) {
     grid.clearScan();
     tracing = false;
     if (grid.scanStart(mode)) {
       gridSet = true;
     }
   }
 }
 public void stopScan(Stack<Coordinate> path) {
   totalruntime = (System.currentTimeMillis() - pathfindStart) / 1000;
   settingsPanel.runtimeLabel.setText("Runtime: " + totalruntime + "s");
   gridSet = false;
   tracing = true;
   this.pathLine = new ArrayList<Coordinate>();
   while (!path.empty()) {
     pathLine.add(path.pop());
   }
 }
  public void run() {
    long start, end, sleepTime;

    while (running) {
      start = System.currentTimeMillis();
      if (gridSet) {
        grid.scanStep();
      }
      repaint();
      end = System.currentTimeMillis();
      // Sleep to match FPS limit
      sleepTime = (1000 / framerate) - (end - start);
      if (sleepTime > 0) {
        try {
          Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
          thread.interrupt();
        }
      }
    }
  }