I have a textfield, and that only accept integer numbers. If user input charter type value it shows JOptionpane Error Message and when user click on the ok button in optionpane message the textfield clear itself

public void nosgetit(DocumentEvent documentEvent){
        DocumentEvent.EventType type = documentEvent.getType();


                String ns=nos_txt.getText();
                char [] c=ns.toCharArray();
                for(int i=0; i < ns.length(); i++){
                   if ( !Character.isDigit(c[i])){
                       JOptionPane.showMessageDialog(null, "You must input number", "ERROR",



What exactly is the question?
You can clear a text field by simply setting its text to "", but remember that will create another call to your DocumentEvent listener, which you may need to handle.