title: How to call Java method in JavaFX menu
body: <p>I'm new to JavaFX. I created this simple menu. </p>
  
  <pre><code>MenuBar menuBar = new MenuBar();
  
          // File menu - new, save, exit
          Menu menu = new Menu("File");
          menu.getItems().add(new MenuItem("New"));
          menu.getItems().add(new MenuItem("Save"));
          menu.getItems().add(new SeparatorMenuItem());
          menu.getItems().add(new MenuItem("Exit"));
  
          menuBar.getMenus().add(menu);
  
          // Options menu - Preferences
          Menu options = new Menu("Options");
          options.getItems().add(new MenuItem("Preferences"));
  
          menuBar.getMenus().add(options);
  
          // Help menu - About
          Menu help = new Menu("Help");
          help.getItems().add(new MenuItem("About"));
  
          menuBar.getMenus().add(help);
  
          menuBar.prefWidthProperty().bind(primaryStage.widthProperty());
  
          root.getChildren().add(menuBar);
          primaryStage.setScene(scene);
          primaryStage.show();
      }
  </code></pre>
  
  <p>Can you tell me how I can call Java method when I click on a menu? Just for a start I wan to call this Java method when I click <code>Exit</code>.</p>
  
  <pre><code> public void programExit(){
  
         System.exit(0);
  
      }
  </code></pre>