update a JLabel to show the current score of a snake game
<p><a href="http://i.stack.imgur.com/5Uczz.png" rel="nofollow">still an error</a>Hello everyone :) I am a java beginner and at the moment I am trying to program a snake game. The snake game is built on a JFrame with a GameGrid on it and some JButtons on a JPanel in the west. In the north I am trying to build a scoreboard on a JLabel where the current Score and the current "running time" should be visible.</p>

<p>the problem:
I sit here since 3 days and I still don't understand how to update the JLabel every second to show the new score and time. How can I update the JLabel in the background, that the compiler is still able to read the next line in the code?</p>

<p><a href="http://i.stack.imgur.com/6PClA.jpg" rel="nofollow">screenshotofthegame</a></p>

<pre><code>import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.*;

import javax.swing.*;

public class menuGui {

    JFrame frame;
    JButton start;
    JButton settings;
    JButton info;
    JButton exit;

    GGSnake snake; // GameGrid wird hier definiert, damit man beim action listener unten zugreifen kann.

public static void main(String[] args) {

    menuGui gui = new menuGui();
    gui.menu(); 
    }

    public void menu() {

        //Frame
        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Panel1 mit Menu JButtons
        JPanel panel1 = new JPanel(new BorderLayout());
        panel1.setLayout(new GridLayout(0,1));
        frame.add(panel1,BorderLayout.WEST);

        //Spielwelt von GGSnake zu Frame hinzufügen
        snake = new GGSnake();
        frame.add(snake, BorderLayout.EAST);

        //Scoreboard
        JLabel scoreBoard = new JLabel("Score " + Snake.getScoreText());
        scoreBoard.setForeground( Color.WHITE );
        scoreBoard.setHorizontalAlignment(JLabel.CENTER);
        frame.add(scoreBoard,BorderLayout.SOUTH);

        //Buttons
        JButton start = new JButton("Spiel starten");
        start.setBounds(120, 40, 160, 40);
        start.addActionListener(new startListener());
        panel1.add(start);

        JButton settings = new JButton("Einstellungen");
        settings.setBounds(120, 120, 160, 40);
        settings.addActionListener(new settingsListener());
        panel1.add(settings);

        JButton info = new JButton("Credits");
        info.setBounds(120, 200, 160, 40);
        info.addActionListener(new infoListener());
        panel1.add(info);

        JButton exit = new JButton("Beenden");
        exit.setBounds(120, 280, 160, 40);
        exit.addActionListener(new exitListener());
        panel1.add(exit);

        frame.setTitle("Snake");
        frame.setSize(560,423);
        frame.setBackground(Color.black);
        frame.setResizable(false);
        frame.setVisible(true);


        snake.requestFocusInWindow(); // --&gt; Tastatureingabe wird direkt auf das "GameGrid" geleitet. 

        }

    //ActionListeners
    class startListener implements ActionListener {

        public void actionPerformed(ActionEvent event) {
            // altes GameGrid entfernen
            frame.remove(snake);
            // neu erstellen und hinzufuegen.
            snake = new GGSnake();
            frame.add(snake, BorderLayout.EAST);

            // frame aktualisieren (weil wir etwas entfernt und hinzugefügt haben).
            frame.validate();
            frame.repaint();
            // input aus Tastatur anfordern
            snake.requestFocusInWindow();

        }
    }
    class settingsListener implements ActionListener {

        public void actionPerformed(ActionEvent event) {

        }
    }
    class infoListener implements ActionListener {

        public void actionPerformed(ActionEvent event) {

        }
    }
    class exitListener implements ActionListener {
        //Anwendung wird geschlossen
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    }
}

import ch.aplu.jgamegrid.*;
import java.util.*;
import java.awt.event.KeyEvent;

class Snake extends Actor {

  private ArrayList&lt;Tail&gt; tailList = new ArrayList&lt;Tail&gt;();
  private static int tailSize = 0;
  private static long startTime;

  public Snake() {

    super(true, "sprites/snakeHead.gif");
    startTime = new Date().getTime();
  }

  public void act() {

    if (gameGrid.kbhit())
    {
      switch (gameGrid.getKeyCode())
      {
        case KeyEvent.VK_UP:
          setDirection(Location.NORTH);
          break;
        case KeyEvent.VK_LEFT:
          setDirection(Location.WEST);
          break;
        case KeyEvent.VK_RIGHT:
          setDirection(Location.EAST);
          break;
        case KeyEvent.VK_DOWN:
          setDirection(Location.SOUTH);
          break;
        default:
          return;
      }
    }

    int lastIndex = tailList.size() - 1;
    Location lastLocation = getLocation();
    if (lastIndex &gt; -1)
    {
      lastLocation = tailList.get(lastIndex).getLocation();
      for (int i = lastIndex; i &gt; 0; i--)
        tailList.get(i).setLocation(tailList.get(i - 1).getLocation());
      tailList.get(0).setLocation(getLocation());
    }
    move();
    if (!isInGrid())
    {
      gameOver();
      return;
    }

    Actor a = gameGrid.getOneActorAt(getLocation(), Tail.class);
    if (a != null)
    {
      gameOver();
      return;
    }

    tryToEat(lastLocation);
  }

  private void gameOver() {

    gameGrid.removeAllActors();
    gameGrid.addActor(new Actor("sprites/gameover.png"), new Location(10, 8));
  }

  private void tryToEat(Location lastLocation) {

    Actor actor = gameGrid.getOneActorAt(getLocation(), Food.class);
    if (actor != null)
    {
      Tail newTail = new Tail();
      gameGrid.addActor(newTail, lastLocation);
      tailList.add(newTail);
      tailSize++;
      actor.removeSelf();
      gameGrid.addActor(new Food(), gameGrid.getRandomEmptyLocation());
    }
  }

  public static String getScoreText() {

      long currentTime = (new Date().getTime() - startTime) / 1000;
      return tailSize + " tail segment(s) at " + currentTime + " s";
  }
}

import ch.aplu.jgamegrid.*;

public class GGSnake extends GameGrid {
    public int startingSpeed = 150;

    public GGSnake() {
        super(20, 20, 20, false);
        this.setBgImagePath("sprites/maxresdefault.jpg");
        this.reset();
        this.doRun();
    }

    public void reset() {
        this.removeAllActors();
        this.setSimulationPeriod(this.startingSpeed);
        Snake snake = new Snake();
        this.addActor((Actor)snake, new Location(10, 10));
        this.addActor((Actor)new Food(), this.getRandomEmptyLocation());
        snake.setDirection(Location.NORTH);
    }
}
</code></pre>