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);
}
}