public class NewJFrame3 extends javax.swing.JFrame {
/**
* Creates new form NewJFrame3
*/
public NewJFrame3() {
initComponents();
}
/**
* This method is called
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);
}
}
});
You will need to attach a DocumentListener to your textfield. See this tutorial for more information.