Random random = new Random();
int position = 10;
//随机绘制4个数字
for (int i = 0; i < 4; i++) {
String content= Integer.toString(random.nextInt(10));
//绘制数字
g.drawString(content,position, 20);
//排列数字的位置
position+=30;
}
//绘制8条干扰线
for (int i = 0; i < 8; i++) {
g.setColor(Color.DARK_GRAY);
//绘制深灰色的干扰线
g.drawLine(random.nextInt(width), random.nextInt(height), random.nextInt(width), random.nextInt(height));
}
//输出图片
ImageIO.write(image ,"jpg", response.getOutputStream());
}