1 import java.awt.*;
2 import java.util.*;
3 import javax.swing.*;
4 import javax.swing.border.LineBorder;
5
6 public class Test extends JFrame
7 {
8
9 public static void main(String[] args) {
10
11 LineBorder lb = new LineBorder(Color.black,2);
12 Test t1 = new Test();
13 t1.setSize(320,200);
14 t1.setLayout(new GridLayout(1,3));
15
16 int[] a = random(3,54);
17
18 for(int i=0;i<3;i++){
19 t1.add(new JLabel(new ImageIcon("card/"+a[i]+".png")));}
20
21 t1.setDefaultCloseOperation(EXIT_ON_CLOSE);
22 t1.setLocationRelativeTo(null);
23 t1.setVisible(true);
24 }
25
26
27 public static int[] random(int number,int max){
28 //从max中产生number个随机数
29 //output number from max value
30 int[] array1 = new int[number];
31 // int[] array2 = new int[max];
32 array1[0] = (int)Math.round(Math.random()*max)+1;
33
34 for(int i = 1; i < number; i++){
35 array1[i] = (int)Math.round(Math.random()*max)+1;
36 for(int j =0; j<i; j++){
37
38 while(array1[i] == array1[j]){
39 array1[i] = (int)Math.round(Math.random()*max)+1;
40 }
41
42 }
43 }
44 return array1;
45 }
46
47 }