title: JavaFX - Getting KeyCode for Enter Key to execute Event with Text Field to go to entered web address
body: <p>I have Tried to get the enter key keycode when the enter key is pressed to go to the entered web address. when I try to do that, it gives me an error.</p>
  
  <p>How can I fix it so it will work?</p>
  
  <pre><code>package fxmlstuffs;
  
  import javafx.fxml.Initializable;
  import java.net.URL;
  import java.util.ResourceBundle;
  import javafx.event.EventHandler;
  import javafx.fxml.FXML;
  import javafx.scene.control.TextField;
  import javafx.scene.web.WebEngine;
  import javafx.scene.input.KeyEvent;
  
  public class FXMLDocumentController implements Initializable {
  
      WebEngine web = new WebEngine();
  
      @FXML
      private TextField url;
  
  
      @Override
      public void initialize(URL location, ResourceBundle resources) {
          assert url != null : "fx:id =\"url\" was not injected: check your FXML file";
  
          url.setOnKeyPressed(new EventHandler&lt;KeyEvent&gt;(){
              @Override
              public void handle(KeyEvent ke){
                  int key = ke.getKeyCode();
                  if(key == KeyEvent.VK_ENTER){
                      web.load(url.getText());
                  }
              }
          });
      }
  }
  </code></pre>
  
  <p>The Specific errors straight from Netbeans:</p>
  
  <p>Error 1:</p>
  
  <pre><code>error: cannot find symbol
                  int key = ke.getKeyCode();
    symbol:   method getKeyCode()
    location: variable ke of type KeyEvent
  </code></pre>
  
  <p>Error 2:</p>
  
  <pre><code>error: cannot find symbol
                  if(key == KeyEvent.VK_ENTER){
    symbol:   variable VK_ENTER
    location: class KeyEvent
  </code></pre>