I've make rules for input validation :
The form :Code:public class TextValidation implements RulesProvider { private RulesSource rulesSource; public TextValidation() { DefaultRulesSource rulesSource = new DefaultRulesSource(); rulesSource.addRules(getRules()); this.rulesSource = rulesSource; } protected Rules getRules() { Rules rules = Rules.createRules(getClass()); Constraints c = Constraints.instance(); rules.add("inputString", c.all(new Constraint[] { c.required(), c.maxLength(8) })); return rules; } public PropertyConstraint getRules(String property) { return rulesSource.getRules(getClass(), property); } }
How I can register my textUserID ?Code:public class Text extends JFrame implements ActionListener { private JTextField textUserID = new JTextField(); private JPasswordField password = new JPasswordField(); private JButton ok = new JButton("Ok"); private JButton cancel = new JButton("Cancel"); private TextValidation validation = new TextValidation(); public Text() { ok.addActionListener(this); FormLayout layout = new FormLayout("r:50dlu,3dlu,80dlu",""); DefaultFormBuilder builder = new DefaultFormBuilder(layout); builder.setDefaultDialogBorder(); builder.append("User ID", textUserID); builder.nextLine(); builder.append("Password",password); builder.nextLine(); builder.append(ButtonBarFactory.buildRightAlignedBar (ok,cancel),3); getContentPane().add(builder.getPanel()); pack(); show(); } public static void main(String args[]) { Text text = new Text(); } public void actionPerformed(ActionEvent e) { String s = e.getActionCommand(); if(s.equals("Ok")) { //here i want to validate value of user ID (textUserID) } } }
Thx before
Ulil


Reply With Quote