title: JavaFX: draw canvas by a pressed button through the Controller
body: <p>I'd like to use a button in order tu get some things drawn on my JavaFX Canvas.</p>
  
  <pre><code>package sample;
  
  import javafx.fxml.FXML;
  import javafx.scene.canvas.Canvas;
  import javafx.scene.canvas.GraphicsContext;
  import javafx.scene.control.Button;
  import javafx.scene.paint.Color;
  import javafx.scene.shape.ArcType;
  import javafx.scene.control.Label;
  
  public class Controller {
  
      @FXML
      Canvas canvas1;
  
      @FXML
      Label label;
  
      public void onButtonPress(){
          System.out.println("test");
          Canvas canvas1 = new Canvas(300, 250);
          GraphicsContext gc = canvas1.getGraphicsContext2D();
          drawShapes(gc);
          label.setText("test");
      }
  
      public void drawShapes(GraphicsContext gc) {
          gc.setFill(Color.GREEN);
          gc.setStroke(Color.BLUE);
          gc.setLineWidth(5);
          gc.strokeLine(40, 10, 10, 40);
          gc.fillOval(10, 60, 30, 30);
      }
  }
  </code></pre>
  
  <p>When I press the Button, nothing happens. The Canvas in the XML file is defined as follows:</p>
  
  <pre><code> &lt;Canvas fx:id="canvas1" height="200.0" layoutX="30.0" layoutY="14.0" width="552.0" /&gt;
  </code></pre>
  
  <p>May anyone help me?</p>