class ValidateTextField extends JTextField{
ValidateTextField(int size){
super(size);
}
protected Document createDefaultModel(){
return new ValidateDocument();
}
}
class ValidateDocument extends PlainDocument{
public void insertString(int offset, String str, AttributeSet a)
throws BadLocationException{
if(str.charAt(0)>=(char)'0'&&str.charAt(0)<=(char)'9')
super.insertString(offset, str, a);
}
}
ValidateTextField(int size){
super(size);
}
protected Document createDefaultModel(){
return new ValidateDocument();
}
}
class ValidateDocument extends PlainDocument{
public void insertString(int offset, String str, AttributeSet a)
throws BadLocationException{
if(str.charAt(0)>=(char)'0'&&str.charAt(0)<=(char)'9')
super.insertString(offset, str, a);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货