Realtime printing of what's typed

后端 未结 2 1290
伪装坚强ぢ
伪装坚强ぢ 2021-01-26 02:52
public class NewJFrame3 extends javax.swing.JFrame {

/**
 * Creates new form NewJFrame3
 */
public NewJFrame3() {
    initComponents();
}

/**
 * This method is called          


        
相关标签:
2条回答
  • 2021-01-26 03:18

    Try something like this :

    // Listen for changes in the text
    textField.getDocument().addDocumentListener(new DocumentListener() {
      public void changedUpdate(DocumentEvent e) {
        warn();
      }
      public void removeUpdate(DocumentEvent e) {
        warn();
      }
      public void insertUpdate(DocumentEvent e) {
        warn();
      }
    
      public void warn() {
         if (Integer.parseInt(textField.getText())<=0){
           JOptionPane.showMessageDialog(null,
              "Error: Please enter number bigger than 0", "Error Massage",
              JOptionPane.ERROR_MESSAGE);
         }
      }
    });
    
    0 讨论(0)
  • 2021-01-26 03:27

    You will need to attach a DocumentListener to your textfield. See this tutorial for more information.

    0 讨论(0)
提交回复
热议问题