Duvida com extends PlainDocument

0 respostas
javaroxxd

Boa Noite, eu gostaria que alguém me explicasse como o Document a baixo funciona, algumas coisas eu entendo só que não conheço a class Document

class MoedaDocument extends PlainDocument{      
        
    private static final long serialVersionUID = 5091878348512314283L;  
  
    boolean isDigit (char c){  
        if (c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9' || c == '0'){  
            return true;  
        }  
        return false;  
    }  
      
    public void remove(int offs, int len) throws BadLocationException {  
                  
        super.remove(offs, len);  
          
        if (len == 1){  
            insertString(0, "", null);  
        }  
    }  
      
    public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {  
        String texto = getText(0,getLength());  
          
        if(texto.length()<10){  
            System.out.println("aqui");  
            remove(0,getLength());  
            System.out.println("aqui2");  
            StringBuffer strBuf = new StringBuffer(texto.replaceAll(",","")+str);  
              
            for (int i = 0; i < strBuf.length(); i++){  
                if (!isDigit(strBuf.charAt(i))){  
                    strBuf.deleteCharAt(i);  
                }  
            }  
            //novo  
            if (strBuf.charAt(0) == '0'){  
                strBuf.deleteCharAt(0);  
            }  
              
            if(strBuf.length() == 1){  
                strBuf.insert(0,"0");  
                strBuf.insert(0,",");  
                strBuf.insert(0,"0");  
            }  
            else if(strBuf.length() == 2){  
                strBuf.insert(0,",");  
                strBuf.insert(0,"0");  
            }  
            else if(strBuf.length() == 0){  
                strBuf.insert(0,"0");  
                strBuf.insert(0,"0");  
                strBuf.insert(0,",");  
                strBuf.insert(0,"0");  
            }  
            else  
                strBuf.insert(strBuf.length()-2,",");  
              
              
              
            super.insertString(0, strBuf.toString(), a);  
        }  
    }  
      
}

Obrigado

Criado 26 de novembro de 2013
Respostas 0
Participantes 1