I am trying to shuffle JButton using collections.shuffle(),but it does not work when I run the program…
this is my code :
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package projetu;
import java.awt.*;
import java.util.*;
/**
*
* @author USER
*/
public class NewMain extends JFrame{
/**
* @param args the command line arguments
*/
final int row =3;
final int col =3;
javax.swing.JPanel panel;
javax.swing.JButton button[];
List<javax.swing.JButton> arrlist = new ArrayList();
public NewMain (){
panel = new javax.swing.JPanel();
panel.setLayout(new GridLayout(row,col));
button = new javax.swing.JButton[9];
for (int i=0; i<9; i++){
button[i] = new javax.swing.JButton(String.valueOf(i));
panel.add(button[i]);
arrlist.add(button[i]);
Collections.shuffle(arrlist);
}
add(panel);
setSize(300,300);
setVisible(true);
} //end of script 0001
public static void main(String[] args) {
// TODO code application logic here
NewMain n=new NewMain();
}
}