title: Can't get integer from JTextField
body: <p>I'm trying to get an integer from a <code>JTextField</code>, but I keep getting a <code>NumberFormatException</code>. I used the code below:</p>
  
  <pre><code>JTextField price = new JTextField();
  price.addActionListener(new ComboListener());
  String inputText = price.getText();
  int inputPrice = Integer.parseInt(inputText);
  </code></pre>
  
  <p>Every site says this is the proper way to do it, so I don't understand what I'm doing wrong.</p>
  
  <p>edit: The full code is here:</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  public class RatePanel extends JPanel {
  
      private double[] rate; // exchange rates
      private String[] currencyName;
      private JLabel result;
  
      public RatePanel() {
          currencyName = new String[]{"Select the currency..",
              "European Euro", "Canadian Dollar",
              "Japanese Yen", "Australian Dollar",
              "Indian Rupee", "Mexican Peso"};
  
          rate = new double[]{0.0, 1.2103, 0.7351,
              0.0091, 0.6969, 0.0222, 0.0880};
  
          JLabel title = new JLabel("How much is that in dollars?");
          title.setAlignmentX(Component.CENTER_ALIGNMENT);
          title.setFont(new Font("Helvetica", Font.BOLD, 20));
          add(title);
          add(Box.createRigidArea(new Dimension(0, 100)));
          JLabel enter = new JLabel("Enter cost of item");
          enter.setAlignmentX(Component.LEFT_ALIGNMENT);
          enter.setFont(new Font("Helvetica", Font.BOLD, 20));
          add(enter);
          JTextField price = new JTextField();
          price.addActionListener(new BoxListener());
          price.setAlignmentX(Component.RIGHT_ALIGNMENT);
          add(price);
          add(Box.createRigidArea(new Dimension(0, 100)));
          JLabel select = new JLabel("Select a currency: ");
          select.setAlignmentX(Component.LEFT_ALIGNMENT);
          select.setFont(new Font("Helvetica", Font.BOLD, 20));
          add(select);
          JComboBox Cbox = new JComboBox(currencyName);
          Cbox.addActionListener(new ComboListener());
          Cbox.setAlignmentX(Component.RIGHT_ALIGNMENT);
          add(Cbox);
          String index = Cbox.getSelectedItem().toString();
      }
  
      public class BoxListener implements ActionListener {
  
          public void actionPerformed(ActionEvent event) {
              String inputText = price.getText();
              int inputPrice = Integer.parseInt(inputText);
          }
      }
  
      public class ComboListener implements ActionListener {
  
          public void actionPerformed(ActionEvent event, String index, double inputPrice, double[] rate) {
              double finalPrice = 0;
              switch (index) {
                  case "European Euro":
                      finalPrice = inputPrice * rate[1];
                      break;
                  case "Canadian Dollar":
                      finalPrice = inputPrice * rate[2];
                      break;
                  case "Japanese Yen":
                      finalPrice = inputPrice * rate[3];
                      break;
                  case "Australian Dollar":
                      finalPrice = inputPrice * rate[4];
                      break;
                  case "Indian Rupee":
                      finalPrice = inputPrice * rate[5];
                      break;
                  case "Mexican Peso":
                      finalPrice = inputPrice * rate[6];
                      break;
              }
  
              result = new JLabel(inputPrice + "USD equals " + finalPrice
                      + index);
              add(result);
          }
  
          @Override
          public void actionPerformed(ActionEvent e) {
              throw new UnsupportedOperationException("Not supported yet.");
          }
      }
  }
  </code></pre>