title: How do I only allow numbers in a JTextField using a KeyEvent?
body: <p>My attempt at this is:</p>
  
  <pre><code>private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {                                       
          char c = evt.getKeyChar();
  
          if(c != '1' &amp;&amp; c != '2' &amp;&amp; c != '3' &amp;&amp; c != '4' 
             &amp;&amp; c != '5' &amp;&amp; c != '6' &amp;&amp; c != '7' &amp;&amp; c != '8'
             &amp;&amp; c != '9' &amp;&amp; c != '0') {
              evt.consume(); 
          } 
  </code></pre>
  
  <p>Which is quite strange, since this is what my book has shown me.</p>
  
  <p>Also, is this viable in comparison to a Formatted Text Field?</p>