title: Java Swing JTextField - Only Numbers
body: <p>I am making a small java Swing Applet that converts temperatures: TempConvert.java</p>
  
  <p>Here is my code:</p>
  
  <pre><code>package swing;
  
  import javax.swing.*;
  import javax.swing.event.*;
  import java.awt.*;
  import java.awt.event.*;
  
  /** Celcius to Fahrenheit Converter
   * @version 1.0
   * @author Oliver Ni
   */
  
  public class TempConvert extends JApplet{
      JLabel result;
      JRadioButton ctof;
      JRadioButton ftoc;
      JTextField deg;
      JLabel degLab;
      JButton convert;
  
      public void convert() {
          if (ctof.isSelected() == true) {
              result.setText("&lt;html&gt;&lt;br&gt;" + Integer.toString(Integer.parseInt(deg.getText()) * 9 / 5 + 32) + "&lt;sup&gt;o&lt;/sup&gt; F&lt;/html&gt;");
          } else if (ftoc.isSelected() == true) {
              result.setText("&lt;html&gt;&lt;br&gt;" + Integer.toString((Integer.parseInt(deg.getText()) - 32) * 5 / 9) + "&lt;sup&gt;o&lt;/sup&gt; C&lt;/html&gt;");
          } else {
              result.setText("&lt;html&gt;&lt;br&gt;Error.&lt;/html&gt;");
          }
      }
  
      public void makeApplet() {
          setLayout(new FlowLayout());
          ctof = new JRadioButton("Celcius to Fahrenheit");
          ftoc = new JRadioButton("Fahrenheit to Celcius");
          convert = new JButton("Convert");
          result = new JLabel("");
          ButtonGroup group = new ButtonGroup();
          group.add(ctof);
          group.add(ftoc);
  
          deg = new JTextField(10);
          degLab = new JLabel("&lt;html&gt;&lt;sup&gt;o&lt;/sup&gt;&lt;/html&gt;");
          convert.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
                  convert();
              }
          });
          add(ctof);
          add(ftoc);
          add(deg);
          add(degLab);
          add(convert);
          add(result);
      }
  
      public void init() {
          try {
              SwingUtilities.invokeAndWait(new Runnable() {
                  public void run() {
                      makeApplet();
                  }
              });
          } catch(Exception e) {
              System.out.println("Error loading because " + e);
          }
      }
  }
  </code></pre>
  
  <p>I want to restrict the <code>JTextField</code> <code>deg</code> to only integers. Is there any way I can do that?</p>
  
  <p>Any help would be appreciated!</p>