Stop user entering letters in GUI, numbers only
I am currently using exception handling to stop users entering letters in a GUI input. So I try to parse String to double and if this code fails I just assume the user has typed in letters or some other characters that cannot be parsed and then I catch and print a message telling them that only numbers are allowed.
Surely there must be a more elegant way to simply stop users trying to type in letters where only numbers are allowed.
x = Double.parseDouble(sx);
y = Double.parseDouble(sy);
Thank you in advance for you help.