Problem: how do you check if there is text in the dialog box before it tries to run the rest of the code.
Solution: if .
int parseToInt(String maybeInt, int defaultValue){ if (maybeInt == null) return defaultValue; maybeInt = maybeInt.trim(); if (maybeInt.isEmpty()) return defaultValue; return Integer.parseInt(maybeInt); }
If you can save the extra dependency, I would pull out Common Lang StringUtils to use StringUtils.isBlank instead of trim / isEmpty, because it also handles Unicode.
Thilo
source share