swing - Java GUI validation -


i have java swing application contains 4 jtextfields, 1 jlabel , 1 jbutton. want user enter integer values in 4 jtextfields , when user presses jbutton sum of integer values should appear in jlabel...now main problem on jbuttons onclicklistener have validate jtextfields , need know jtextfield had invalid entry...i thinking of implementing separate try-catch block each jtextfield , using integer.parseint(string s) in jbutton's onclicklistener way know jtextfield causing problems...but wont implementing separate try-catch block each jtextfield inefficient??? can suggest better approach...

but wont implementing separate try-catch block each jtextfield inefficient???

inefficient? that's hardly issue when you're checking 4 jtextfields, , shouldn't part of consideration in instance. instead, i'd concentrate more on gui ease of use , safety. consider preventing user entering in non-numeric data in first place, using jspinner or jformattedtextfield or using documentfilter. consider leaving jbutton, or better, it's action, disabled, until 4 text fields filled. make gui more idiot-proof.


as per jb nizet's comment:

i'd concentrate on maintainability, , avoid repeating same block of code 4 times. use array or list store 4 buttons, , use loop make same thing 4 buttons.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -