自己写个类,扩展PlainDocument
如public class test extends PlainDocument
自己写insertString(int offset,String s ,AttributeSet attr)方法
在这个方法中判断如果是数字以外的字符不处理
textfield.setDocument(new test());