日期:2014-05-20 浏览次数:20922 次
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
public class NumOnly extends PlainDocument{
public void insertString(int offs,String str,AttributeSet a) throws BadLocationException{
for(int i=0;i<str.length();i++){
if(str.charAt(i)<'0'||str.charAt(i)>'9'){
return;
}
}
super.insertString(offs,str,a);
}
}