To prevent the textfield from printing characters you'll have to catch those events in your derivation from textfield. So if the key pressed is no number (!isDigit) then consume the event and therefore no non-number key will be accepted.

==============================================================
import java.awt.*;
import java.awt.event.*;

public class NumberTextField extends TextField implements KeyListener
{
public NumberTextField()
{
super();
addKeyListener(this);

}

public void keyPressed(KeyEvent e)
{
}
public void keyReleased(KeyEvent e)
{
}
public void keyTyped(KeyEvent e)
{
char inkey = e.getKeyChar();
if (!Character.isDigit(inkey)) e.consume();
}

public static void main(String args[])
{
Frame f = new Frame();
f.add(new NumberTextField());
f.pack();
f.setVisible(true);
}
}