I have 2 classes. Foo is a bunch of inter-related text fields, and Bar implements those fields and does all the error checking. I don't want the user leaving a text field when it has invalid data.
There are a bunch of checks between Bars that Foo understands and Bar knows nothing about. As Bar is getting the keystroke events it needs to do the verification. So how does Foo tell Bar how to validate the field?
I've googled it but, too be honest, my Java isn't yet good enough for me to understand what they're talking about and the examples seem, quite frankly, stupid and meaningless.
There are a bunch of checks between Bars that Foo understands and Bar knows nothing about. As Bar is getting the keystroke events it needs to do the verification. So how does Foo tell Bar how to validate the field?
Code:
class Foo {
Foo() {
Bar bar = new Bar(validateRoutine);
}
boolean validateRoutine(Blatz b) {
return isvalid(b);
}
}
class Bar {
JTextField textField;
boolean goNoGo;
Bar(boolean validate) {
goNogo = validate;
textField = new JTextField();
addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent event) {
char key = event.getKeyChar();
Blatz b = new Blatz(key);
if(goNoGo(b)) {
// w00t!
} else {
// BTW, how do I flash textField.background() red for
// half a second or so?
}
}
});
}
}
I've googled it but, too be honest, my Java isn't yet good enough for me to understand what they're talking about and the examples seem, quite frankly, stupid and meaningless.