public classVerificationCode {
Random rand= newRandom();/*** 随机产生的加数和被加数*/
private int jiashu=0;private int beijiashu=0;/*** 随机产生的计算方式,0表示加,1表示减*/
private int js=0;private char[] aa={'零','壹','贰','叁','肆','伍','陆','柒','捌','玖'};private char[] action={'加','减'};private char[] jieguo={'等','是'};public static voidmain(String[] args) {
VerificationCode code=newVerificationCode();
JFrame jFrame=newJFrame();
jFrame.setBounds(400, 400, 250, 250);
ImageIcon img= newImageIcon(code.getVerificationCode2());
JLabel background= newJLabel(img);
jFrame.add(background);
jFrame.setVisible(true);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}/*** 第二种验证码的计算方式,两位数的加减法
*@return一个新的验证码图片*/
publicBufferedImage getVerificationCode2()
{int width=200;int height=100;int degree=0;//继续一共旋转的角度,方便最后的时候旋转回来
BufferedImage image = newBufferedImage(width, height,
BufferedImage.TYPE_4BYTE_ABGR);//获取图形上下文
Graphics g =image.getGraphics();//画随机干扰框
setSquareBackGround(g,width,height,5);//画干扰点//CreateRandomPoint(width, height,50,g,255);//随机画几条线//CreateRandomLine(width, height,2,g,255);//设定背景色
Color background=getColor(180);
g.setColor(background);
g.fillRect(0, 0, width, height);//画边框
g.setColor(background);
g.drawRect(0,0,width-1,height-1);//将认证码显示到图像中,如果要生成更多位的认证码
char[] content=getDrawContent2();int[] xs=getRadonWidths(width,content.length);int[] ys=getRadomHeights(height,content.length);for(int i=0;i
{ String s=content[i]+"";if(content[