Validation is the keyword.
No matter if you create your own or use a mechanism that is provided, you just need to validate before you move on:
public class CustomVerifier extends InputVerifier {
@Override
public boolean verify(JComponent input) {
String text = ((JTextField) input).getText();
return true;
}
}
and add to the JTextfield:
oTextField.setInputVerifier(new CustomVerifier());
You can also use a listener (propertyChange, focus) and validate there.
EDIT:
Do I need to mention that you need to make a custom JDialog for this? I guess not. Have fun.
EDIT 2:
Version 1 with a Listener:
textField.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent oEvent) {
String strContent = textField.getText();
try {
int i = Integer.parseInt(strContent);
if(i<=0 || i>=1000) {
JOptionPane.showMessageDialog(null, "This number is <1 or >999.");
}
} catch (NumberFormatException oException) {
JOptionPane.showMessageDialog(null,"This is not even a number.");
}
});
}
}
Version2 with InputVerifyer:
textField.setInputVerifier(new InputVerifier() {
@Override
public boolean verify(JComponent input) {
String strContent = textField.getText();
try {
int i = Integer.parseInt(strContent);
if(i<=0 || i>=1000) {
JOptionPane.showMessageDialog(null, "This number is <1 or >999.");
}
} catch (NumberFormatException oException) {
JOptionPane.showMessageDialog(null, "This is not even a number.");
}
return true;
}
});
I hope Edit2 helps. You need to learn that!
Please buy a book to get such information without knowing the keywords.