该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
public class button extends JPanel implements MouseListener, ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private JButton[] button;
private ImageIcon[] puzzlep;
private JButton kbbutton;
private static final String[] IMAGES = { "images/f-0.jpg",
"images/f-1.jpg", "images/f-2.jpg", "images/f-3.jpg",
"images/f-4.jpg", "images/f-5.jpg", "images/f-6.jpg",
"images/f-7.jpg", "images/f-8.jpg", "images/f-9.jpg",
"images/f-10.jpg", "images/f-11.jpg", "images/f-12.jpg",
"images/f-13.jpg", "images/f-14.jpg", "images/f-15.jpg",
"images/f-16.jpg", "images/f-17.jpg", "images/f-18.jpg",
"images/f-19.jpg", "images/f-20.jpg", "images/f-21.jpg",
"images/f-22.jpg", "images/f-23.jpg", "images/f-222.jpg" };
public button() {
this.setLayout(new GridLayout(5, 5));
puzzlep = new ImageIcon[IMAGES.length];
for (int i = 0; i < IMAGES.length; i++) {
puzzlep[i] = new ImageIcon(IMAGES[i]);
}
button = new JButton[25];
for (int i = 0; i < 25; i++) {
button[i] = new JButton();
button[i].setFocusable(false);
button[i].setIcon(puzzlep[i]);
button[i].setActionCommand(String.valueOf(i));
button[i].addActionListener(this);
this.add(button[i]);
}
//this.remove(button[24]);
//kbbutton = new JButton();
//this.add(kbbutton);
}
public void start() {
int length=25;
int[] shuffled = new int[length];
boolean[] bool = new boolean[length]; //the length must equals to length
Random rand = new Random();
int num = 0;
for(int i = 0; i < length;i++){
do{
num = rand.nextInt(length);
}while(bool[num]);
bool[num] =true;
shuffled[i] = num;
button[i].setIcon(puzzlep[shuffled[i]]);
}
}
public void yidong(){
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}