nl.captcha
Class Captcha

java.lang.Object
  extended by nl.captcha.Captcha
All Implemented Interfaces:
java.io.Serializable

public final class Captcha
extends java.lang.Object
implements java.io.Serializable

A builder for generating a CAPTCHA image/answer pair.

Example for generating a new CAPTCHA:

Captcha captcha = new Captcha.Builder(200, 50)
        .addText()
        .addBackground()
        .build();

Note that the build() must always be called last. Other methods are optional, and can sometimes be repeated. For example:

Captcha captcha = new Captcha.Builder(200, 50)
        .addText()
        .addNoise()
        .addNoise()
        .addNoise()
        .addBackground()
        .build();

Adding multiple backgrounds has no affect; the last background added will simply be the one that is eventually rendered.

To validate that answerStr is a correct answer to the CAPTCHA:

captcha.isCorrect(answerStr);

Author:
James Childers
See Also:
Serialized Form

Nested Class Summary
static class Captcha.Builder
           
 
Field Summary
static java.lang.String NAME
           
 
Method Summary
 java.lang.String getAnswer()
           
 java.awt.image.BufferedImage getImage()
          Get the CAPTCHA image, a PNG.
 java.util.Date getTimeStamp()
           
 boolean isCorrect(java.lang.String answer)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME

public static final java.lang.String NAME
See Also:
Constant Field Values
Method Detail

isCorrect

public boolean isCorrect(java.lang.String answer)

getAnswer

public java.lang.String getAnswer()

getImage

public java.awt.image.BufferedImage getImage()
Get the CAPTCHA image, a PNG.

Returns:
A PNG CAPTCHA image.

getTimeStamp

public java.util.Date getTimeStamp()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2010-2011 James Childers. All Rights Reserved.