Verification code This article will teach you how to use JavaBean step-by-step to achieve the entire process of producing color verification code, and provide source code.
FileName: Image.java
=====================================
/*
* Created on 2004-8-4
*
* To change the template for this generated file go
* Window>preferences>java>code Generation>code and Comments
*/
Package myclass.test;
Import java.awt.*;
Import java.awt.image.*;
Import java.util.*;
/**
* @author
*
* To change the template for this generated type comment go
* Window>preferences>java>code Generation>code and Comments
*/
public class Image {
Public String srand= "";
Public color getrandcolor (int fc,int BC) {//random color for a given range
Random Random = new Random ();
if (fc>255) fc=255;
if (bc>255) bc=255;
int R=fc+random.nextint (BC-FC);
int G=fc+random.nextint (BC-FC);
int B=fc+random.nextint (BC-FC);
return new Color (R,G,B);
}
Public BufferedImage Creatimage () {
Create an image in memory
int width=60, height=20;
BufferedImage image = new BufferedImage (width, height, bufferedimage.type_int_rgb);
Get Graphics context
Graphics g = image.getgraphics ();
Generate Random Class
Random Random = new Random ();
Set Background color
G.setcolor (Getrandcolor (200,250));
G.fillrect (0, 0, width, height);
Set font
G.setfont (New Font ("Times New Roman", font.plain,18));