eva/3 Application BuilderDeveloping eva/3 ApplicationsCommon InformationsCommon Properties 

InputVerifier

Entries of a bean can be verified with the InputVerifier. So it can be experienced if an input only contains numbers. If an invalid value will be detected, the background color of the SFormattedField can be painted red.

To verify the input, a class, extending the Swing class InputVerifier, must be set in the Properies dialog using theClass selection dialog.

Beispiel:

package mypackage;

import java.awt.Color;
import java.util.regex.Pattern;

import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

import com.odc.eva3.rt.se.beans.SFormattedField;

public class NumberVerifier extends InputVerifier {

    public boolean verify(JComponent input) {
        SFormattedField field = (SFormattedField) input;
        String value = ((SFormattedField) input).getText();
        if (value == null || value.length() == 0) {
            field.setBackground(new Color(245, 245, 245));
            return true;
        }
        if (!Pattern.matches("\\d*", value)) {
            field.setBackground(new Color(234, 0, 0));
            new Message().action(new String[] { "Bitte geben Sie nur Zahlen ein",
            "Eingabefehler" }, null);
            return false;
        }
        if (Pattern.matches("\\d*", value)) {
            field.setBackground(new Color(245, 245, 245));
            return true;
        }
        return true;
    }
}