Need an Input Validation in a Java program(Java 2 SE) -


i had made java program in supposed take input user in gui frame , store in .dat file in row , columns. problem particular code not giving desired results. user should able enter numbers between 20 30 using keylistener. input should not accept number out of range, i.e, 19 or 31. eclipse throwing error 'invalid character constant'. there way out?

// input validation restricts user enter specific number range between 20 , 30  txdeposit.addkeylistener(new keyadapter() {     public void keytyped(keyevent ke) {         char c = ke.getkeychar();         if(!(ke.getkeychar() >= '20' && ke.getkeychar() <= '30')) {             gettoolkit().beep();             ke.consume();         }     } }); 

your code cannot compiled because `` used mark characters, not string. character constant consist of 1 , 1 character only. therefore'20'` invalid.

now, far understand want capture numbers 20 30. 2 digit number consists of 2 digits , therefore have make validation more sophisticated: if first character 2 have wait characters 0 9, if first character '3' '0' allowed.

once 2 characters entered have reset state , wait '2' or '3' again.

i doubt want this. far understand added listener text field, didn't you? in case not check entered character. check content of text field:

int number = integer.parseint(tx.gettext()); if (number < 20 || number > 30) {     gettoolkit().beep(); } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -