off the top of my head
class question { int lhs, int rhs, boolean plus;
void randomize() { lhs=math.random()*10, rhs=math.random()*10;
plus=math.random()>0.5;}
string tostring() { return ""+lhs+" "+((plus)?"+":"-")+" "+rhs; }
boolean check(int answer) { if (plus) return answer==lhs+rhs else
return answer==lhs-rhs; }
class answerfield extends textfield<integer> {
private final imodel<question> question;
public answerfield(string id, imodel<question> question) {
super(id, new model<integer>());
this.question=question;
add(new ivalidator<integer> {
public void validate(validatable<integer> validatable) {
if (!question.check(validatable.getvalue()) {
validatable.error(new validationerror("are you
smarter then a first grader?"));
});
}
protected void ondetach() { question.detach(); super.ondetach(); }
}
class mathcaptchapanel extends panel {
private final question question=new question();
public mathcaptchapanel(string id) {
add(new label("question", new propertymodel(this, "question"));
add(new answerfield("answer", new propertymodel(this, "question"));
}
protected void onbeforerender() { question.randomize();
super.onbeforerender(); }
}
-igor
On Mon, May 3, 2010 at 1:13 PM, Thomas Götz <[email protected]> wrote:
> Did anyone ever integrate some kind of math capture with Wicket ("please
> solve the following simple equation ...")? How would I do this, someone got
> a code pointer for me?
>
> -Tom
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]