import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
public class Main{
public static void main(String[] args) {
int width = 150;
int height = 80;
BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.gray);
g.fillRect(0, 0, width, height);
String str = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
g.setColor(Color.RED);
g.setFont(new Font("宋体", Font.BOLD, 34));
int x = 25;
int y = 45;
Random random = new Random();
for(int i=0; i<4; i++){
int index = random.nextInt(str.length());
//str.get(index);用于集合
char c = str.charAt(index);
g.drawString(String.valueOf(c), x, y);
x += 25;
}
try {
ImageIO.write(image, "jpg", new File("C:\\Users\\LuXin\\Pictures\\aaa.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
}
}