package demo;

import java.awt.Color;
import java.awt.Font;
import java.io.OutputStream;

/**
 * <p>验证码抽象类,暂时不支持中文</p>
 *
 * @author: wuhongjun
 * @version:1.0
 */
public abstract class Captcha extends Randoms
{
    protected Font font = new Font("Verdana", Font.ITALIC|Font.BOLD, 28);   // 字体
    protected int len = 5;  // 验证码随机字符长度
    protected int width = 150;  // 验证码显示跨度
    protected int height = 40;  // 验证码显示高度
    private String chars = null;  // 随机字符串

    /**
     * 生成随机字符数组
     * @return 字符数组
     */
    protected char[] alphas()
    {
        char[] cs = new char[len];
        for(int i = 0;i<len;i++)
        {
            cs[i] = alpha();
        }
        chars = new String(cs);
        System.out.println(chars);
        return cs;
    }
    public Font getFont()
    {
        return font;
    }

    public void setFont(Font font)
    {
        this.font = font;
    }

    public int getLen()
    {
        return len;
    }

    public void setLen(int len)
    {
        this.len = len;
    }

    public int getWidth()
    {
        return width;
    }

    public void setWidth(int width)
    {
        this.width = width;
    }

    public int getHeight()
    {
        return height;
    }

    public void setHeight(int height)
    {
        this.height = height;
    }

    /**
     * 给定范围获得随机颜色
     * @return Color 随机颜色
     */
    protected Color color(int fc, int bc)
    {
        if (fc > 255)
            fc = 255;
        if (bc > 255)
            bc = 255;
        int r = fc + num(bc - fc);
        int g = fc + num(bc - fc);
        int b = fc + num(bc - fc);
        return new Color(r, g, b);
    }

    /**
     * 验证码输出,抽象方法,由子类实现
     * @param os 输出流
     */
    public abstract void out(OutputStream os);

    /**
     * 获取随机字符串
     * @return string
     */
    public String text()
    {
        return chars;
    }
}
最近下载更多
代码男神2019  LV10 2021年11月21日
17665202833  LV2 2021年7月1日
天险无涯  LV15 2021年2月2日
846173996  LV2 2021年1月26日
数据库1  LV12 2020年7月11日
gan857569302  LV9 2020年6月28日
104227972  LV1 2020年4月24日
rainsheep  LV5 2020年4月1日
Alex_zpy  LV13 2020年3月4日
zengtianzhi  LV2 2019年12月14日
最近浏览更多
EFWAGGFAWGR 2023年10月19日
暂无贡献等级
zxh2023  LV1 2023年6月30日
12522425  LV13 2023年4月15日
dxn111 2022年11月28日
暂无贡献等级
张好好  LV1 2022年10月26日
tianli3000  LV7 2022年4月28日
JohnAlex  LV9 2022年1月29日
17798830  LV14 2022年1月25日
代码男神2019  LV10 2021年11月21日
zhaoxu123123  LV10 2021年9月9日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友