title: Graphics Context will only draw in one thread
body: <p>I am making a game of snake, but whenever I try to update my canvas in the <code>draw()</code> method, the new snake won't draw. It draws in the <code>run</code> thread. I have tried a bunch of different things, but I can't seem to get it working.</p>
  
  <p><strong>Imports:</strong></p>
  
  <pre><code>import javafx.application.Application;
  import javafx.event.*;
  import javafx.scene.*;
  import javafx.stage.*;
  import javafx.scene.control.*;
  import javafx.scene.layout.*;
  import javafx.geometry.*;
  import java.io.*;
  import java.util.*;
  import javafx.scene.input.KeyEvent;
  import javafx.event.EventHandler;
  import javafx.scene.text.Text;
  import javafx.scene.text.Font;
  import javafx.scene.text.*;
  import javafx.scene.paint.*;
  import javafx.scene.canvas.*;
  </code></pre>
  
  <p><strong>Actual class:</strong></p>
  
  <pre><code>public class Snake extends Application implements Runnable
  {
      //Snake parts and locations
      boolean dead;
      int headX=0;
      int headY=0;
      // for the game
      Group root = new Group();
      Scene snakeG = new Scene(root, 550, 550,Color.BLACK);
      final Canvas canvas = new Canvas(550,550);
      GraphicsContext gc = canvas.getGraphicsContext2D();
      //Start Game
      VBox newGame = new VBox(3);
      Scene startC = new Scene(newGame, 200, 200);
      Label info = new Label("Snake Game \nCreated by: Austin");
      Label rules = new Label("Rules\n1.) If you hit the edge you die\n2.) If you touch your snake you die\n3.)Collect fruit to increase your snakes size");
      Button startBut = new Button("Start Game");
      Stage startS;
  
      public static void main ( String[] args )
      {
          launch(args);
      }
  
      @Override
      public void start ( Stage primaryStage )throws Exception
      {
          startS=primaryStage;
          startS.setTitle("Snake");
          newGame.getChildren().addAll(info,rules,startBut);
          newGame.setAlignment(Pos.CENTER);
          startS.setScene(startC);
          startS.show();
  
          startBut.setOnAction(e -&gt;
          {
              startGame();
          });
      }
  
      public void startGame()
      {
          System.out.println("Success");
          headX=275;
          headY=275;
          dead = false;
          gc.clearRect(0,0,800,800);
          startS.setScene(snakeG);
          gc.setFill(Color.GREEN);
          gc.fillRect(headX,headY,10,10);
          root.getChildren().add(canvas);
          (new Thread ( new Snake())).start();    
      }
  
      public void run()
      {
          draw(); 
      }
  
      // draws the snake
      public void draw()
      {
          System.out.println("DRAW STARTED");
          gc.setFill(Color.GREEN);
          gc.fillRect(50,50,10,10);   
      }
  }
  </code></pre>
  
  <p>If you know of a better way to draw graphics in JavaFX, please tell me. This is the only way I could find for what I am doing. </p>