我正在尝试根据 Random() 方法的生成显示随机图片(只是尝试像验证码之类的东西)。我正在从数组中生成随机编号,但不知道如何将这些编号与图像映射。有任何想法吗 ?到目前为止我所做的:
导入 java.util.Arrays;导入 java.util.Random;
公共类 Gen_Captcha {
static String[] myCaptchaLetters = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9"};
Gen_Captcha captcha= new Gen_Captcha();
public static void main(String[] args) {
Random randomGenerator = new Random();
for(int i=0;i<5;i++){
int random = randomGenerator.nextInt(62);
System.out.print((myCaptchaLetters[random]));
}
}
}
}
注意:以上代码不包含显示图片的swing框架代码。