JTextField NetBeans

0

Good I would like to know if someone can tell me how I could control with the Keytyped that the user enter only vowels and in another textfield only consonants

I have here a reference that only leaves me letters in general and no number or spaces:

char c = evt.getKeyChar();
        if((c<'a' || c>'z') && (c<'A' || c>'Z') && (c<' ' || c>' ')) evt.consume();
    
asked by officaloscarcasi 05.05.2017 в 12:28
source

1 answer

0

Use the method . Matches () of the String class, accompanied by a regular expression in each case:

// Vocales:
String vocales = jTextField1.getText();
if (vocales.matches("[aeiou]+")) {
    // bla bla bla...
}

// Consonantes:
String consonantes = jTextField2.getText();
if (consonantes.matches("[^aeiou]+")) {
    // bla bla bla...
}
    
answered by 05.05.2017 в 13:59