title: Common method for the JTextFields to accept only numbers
body: <p>I limit my <code>JTextFields</code> to accept only numbers. I was using following code for this.</p>
  
  <pre><code>  // my textboxes
    t1=new JTextField(10);
    t2=new JTextField(10);
    t3=new JTextField(10);
  
    // for the first one
    t1.addKeyListener(new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();
            if (!((c &gt;= '0') &amp;&amp; (c &lt;= '9') ||
               (c == KeyEvent.VK_BACK_SPACE) ||
               (c == KeyEvent.VK_DELETE))) {
              getToolkit().beep();
              e.consume();
            }
          }
        });
  </code></pre>
  
  <p>Suppose I have 20 <code>texboxes</code> which need the same validation check. So do we need to write this code 20 times? Can I write a common method to implement this? I am new to <code>Swing</code>.</p>