0

I have a method that validates whether the correct input is entered into a textfield but I would love to perform some junit test on this how could this be done? Any guidance would be greatly appreciated.

public void number_validator(JTextField txtField) {
    textField.addKeyListener(new KeyAdapter() {
        public void keyTyped(KeyEvent e) {
            char character = e.getKeyChar();
                if (!(Character.isDigit(character) || (character == KeyEvent.VK_BACK_SPACE) || (character == KeyEvent.VK_DELETE))) {
                    e.consume();
                    JOptionPane.showMessageDialog(null, "Only a number is allowed in this field.\nNo characters!", "WARNING", JOptionPane.WARNING_MESSAGE);
                }
        }
    });
}
Rebecca
  • 45
  • 5
  • You might want to look at https://stackoverflow.com/questions/11093326/restricting-jtextfield-input-to-integers – Progman Apr 06 '20 at 18:49
  • Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then check the [help/on-topic] to see what questions you can ask. Please see: [Why is β€œCan someone help me?” not an actual question?](http://meta.stackoverflow.com/q/284236). – Progman Apr 06 '20 at 18:49

0 Answers0