⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yanzhenma.java

📁 超市管理系统 运行环境JDK1.4以上 JB2006 源代码公开
💻 JAVA
字号:
package com.aptech.view;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;

import javax.imageio.ImageIO;

public class Yanzhenma {
    public Yanzhenma() {

    }
    private char map[] = {
                         '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
    };

    public String getMap(int width, int height, OutputStream os) {
        if (width <= 0) {
            width = 60;
        }
        if (height <= 0) {
            height = 20;
        }
        BufferedImage image = new BufferedImage(width, height,
                                                BufferedImage.TYPE_INT_RGB);

        Graphics g = image.getGraphics();

        g.setColor(new Color(0xc7c7c7));
        g.fillRect(0, 0, width, height);

        g.setColor(new Color(0xc7c7c7));
        g.drawRect(0, 0, width - 1, height - 1);
        String strmap = "";
        for (int i = 0; i < 4; ++i) {
            strmap += map[(int) (map.length * Math.random())];
        }

        g.setColor(Color.black);
        g.setFont(new Font("Atlantic Inline", Font.PLAIN, 18));
        String str = strmap.substring(0, 1);
        g.drawString(str, 8, 17);

        str = strmap.substring(1, 2);
        g.drawString(str, 20, 15);
        str = strmap.substring(2, 3);
        g.drawString(str, 35, 18);

        str = strmap.substring(3, 4);
        g.drawString(str, 45, 15);

        Random rand = new Random();
        for (int i = 0; i < 10; i++) {
            int x = rand.nextInt(width);
            int y = rand.nextInt(height);
            g.drawOval(x, y, 1, 1);
        }

        g.dispose();

        try {
            ImageIO.write(image, "JPEG", os);
        } catch (IOException e) {
            return "";
        }

        return strmap;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -