title: Java: I want to get TextField value when I clicked a button. How to do it?
body: <pre><code>public Monster createCharacterScene() {
      String name;
      TextField nameTextField = new TextField();
      nameTextField.setLocation(65, 50);
      nameTextField.setSize(60, 10);
      Button myButton = new Button("OK");
      myButton.setLocation(25, 50);
      myButton.setSize(30, 40);
      add(myButton);
      add(nameTextField);
      myButton.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
              name = nameTextField.getText();
          }
      });
      return null;
  }
  </code></pre>
  
  <p>I can't do it like this. They says "local variables referenced from an inner class must be final or effectively final". Is there alternative way to do it?</p>
  
  <p>Thanks a lot.</p>
  
  <p>PS. I using applet.</p>