Ai galera estou fazendo um classe que extende PlainDocument so que alem de limitar caratcteres, ele tb tem uma funções para so aceitar NUMEROS, ou so ALFA,entradas Somente MAIUSCULAS ou MINUSCULAS, minha duvida e na implementação da função de so aceitar numeros ou so alfa, em C/C++ eu trasformava o caracter em ascii e verificava seu intervalo para determinar se ele era um numero ou não em JAVA ou não sei como fazer isso ? ai galera da uma ajudinha, segue o codigo fonte abaixo, podem copiar e GPL
!!!
/*
* DocumentPro.java
*
* Created on 29 de Janeiro de 2003, 09:10
*/
package util;
/**
*
* @author William J. Oliveira
*/
import javax.swing.*;
import javax.swing.text.*;
public class DocumentPro extends PlainDocument {
public static final int NORMAL = 0;
public static final int NUMERICO = 1;
public static final int TEXTO = 2;
public static final int MAIUSCULA = 3;
public static final int MINUSCULA = 4;
private int iMaxLength;
private int iTipo;
public DocumentPro() {
super();
this.iMaxLength = 0;
this.iTipo = 0;
}
public DocumentPro(int maxlen) {
super();
this.iMaxLength = maxlen;
this.iTipo = 0;
}
public DocumentPro(int maxlen, int tipo) {
super();
this.iMaxLength = maxlen;
this.iTipo = tipo;
}
public void setMaxlen(int maxlen){
iMaxLength = maxlen;
}
public int gettMaxlen(){
return this.iMaxLength;
}
public void setTipo(int tipo) {
this.iTipo = tipo;
}
public int getTipo() {
return this.iTipo;
}
public void insertString(int offset, String str, AttributeSet attr)
throws BadLocationException {
if (str == null) return;
switch(this.iTipo) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
str=str.toUpperCase();
break;
case 4:
str=str.toLowerCase();
break;
}
if (iMaxLength <= 0) // aceitara qualquer no. de caracteres
{
super.insertString(offset, str, attr);
return;
}
int ilen = (getLength() + str.length());
if (ilen <= iMaxLength){ // se o comprimento final for menor...
super.insertString(offset, str, attr); // ...aceita str
} else {
if (getLength() == iMaxLength) return; // nada a fazer
String newStr = str.substring(0, (iMaxLength - getLength()));
}
}
}
falow