title: How can I interact with my canvas in the FXMLDocumentController
body: <p>I want to draw pixels on my canvas after pushing a button (so in the handleButtonAction function of my FXMLDocumentController)</p>
  
  <pre class="lang-java prettyprint-override"><code>public class FXMLDocumentController implements Initializable {
  
      @FXML
      private Label label;
      private Canvas canvas;
  
      @FXML
      private void handleButtonAction(ActionEvent event) {
          //I'd like to perform the interaction with the Canvas here
      }
  
      @Override
      public void initialize(URL url, ResourceBundle rb) {
          // TODO
      }    
  
  }
  </code></pre>
  
  <p>but everywhere I looked I only saw examples where the canvas was changed in the start function like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class BasicOpsTest extends Application {
  
      public static void main(String[] args) {
          launch(args);
      }
  
      @Override
      public void start(Stage primaryStage) {
          primaryStage.setTitle("Drawing Operations Test");
          Group root = new Group();
          Canvas canvas = new Canvas(300, 250);
          GraphicsContext gc = canvas.getGraphicsContext2D();
          drawShapes(gc);
          root.getChildren().add(canvas);
          primaryStage.setScene(new Scene(root));
          primaryStage.show();
      }
  
      private void drawShapes(GraphicsContext gc) {
          gc.setFill(Color.GREEN);
          gc.setStroke(Color.BLUE);
          gc.setLineWidth(5);
          gc.strokeLine(40, 10, 10, 40);
      }
  }
  </code></pre>
  
  <p>is there a way to do that?</p>