textfield

Number Validation: Only numbers in TextField using Java GUI

Submitted by donbermoy on
Some of my students before always asked how to filter a textbox with only numbers that can be inputted. Right away, they always made a mistake on writing the code because they are just using the NumberFormatException code. But actually it isn't wrong, it is just sometimes not applicable and not functioning at times when I can still remember my college days. But now, I wrote this code to filter numbers on textbox or any controls in Java. I want to share and teach about this code. Now let's begin this tutorial! 1.