JAVA电子密保生成

import java.awt.*;   
import java.awt.image.*;   
import java.io.*;   
import java.util.Random;

import javax.imageio.*;   

import java.awt.font.*;   
import java.awt.geom.*;   

/**
 * JAVASecret security card generates
 * @author Administrator
 *    Carefree (mail: xf_taoran@163.com)
 *    welcomes exchange of common learning
 *
 */
public class CreatePasswordProtection {   
 public static void main(String[] args) throws Exception {   
  int width = 400;   
  int height = 300;  
  String title = "E-secret security card";
  
  String index = "Serial Number : ";
  
  String[] xindex = {"1","2","3","4","5","6"};
  
  String[] yindex = {"A","B","C","D","E","F"};
  

  Random random = new Random();
  File file = new File("c:/image.jpg");   
     
  Font font = new Font("Serif", Font.BOLD, 14);   
  BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);   
  Graphics2D g2 = (Graphics2D)bi.getGraphics();   
  g2.setBackground(Color.WHITE);   
  g2.clearRect(0, 0, width, height);   
  g2.setPaint(Color.RED);   
/
  FontRenderContext context0 = g2.getFontRenderContext();   
  Rectangle2D bounds0 = font.getStringBounds(index, context0);
  double x0 = 2;   
  double y0 = 2;   
  double ascent0 = -bounds0.getY();   
  double baseY0 = y0 + ascent0;  
  g2.drawString(title, (int)x0, (int)baseY0);   
/
  FontRenderContext context = g2.getFontRenderContext();   
  Rectangle2D bounds = font.getStringBounds(index, context);
  double x = (width - 350);   
  double y = (height - 250);   
  double ascent = -bounds.getY();   
  double baseY = y + ascent;  
  index = index+(random.nextInt(8999)+1000)+" "+(random.nextInt(8999)+1000)+" "+(random.nextInt(8999)+1000)+" "+(random.nextInt(8999)+1000);
  g2.drawString(index, (int)x, (int)baseY);   
/
  for (int i = 0; i < xindex.length; i++) {
   double xx = (width - 350) + 40*(i+1);   
   double yx = (height - 250) + 30;   
   g2.drawString(xindex[i], (int)xx, (int)yx);
  }
/
  for (int i = 0; i < yindex.length; i++) {
   double xy = (width - 350) - 10;   
   double yy = (height - 250) + 30 + 30*(i+1);   
   g2.drawString(yindex[i], (int)xy, (int)yy);
  }

  for (int j = 0; j < 7; j++) {
   g2.drawLine(69, 85+30*j, 309, 85+30*j);
   g2.drawLine(69+40*j, 85, 69+40*j, 265);
  }

  for (int j = 0; j < 6; j++) {
   for (int i = 0; i < 6; i++) {
    int sj = random.nextInt(999);
    double xx = (width - 350) - 10 + 40*(i+1);   
    double yx = (height - 250) + 50 + 30*j;    
    g2.drawString(String.valueOf(sj), (int)xx, (int)yx);
   }
  }
  
  ImageIO.write(bi, "jpg", file);   
    }   

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值