加上date数组打乱图片后,图片不显示
package puzzle;
import javax.swing.*;
import java.util.Random;
public class GameJFrame extends JFrame {
int [][] date=new int[4][4];
public GameJFrame(){
initJFrame();
initJMenu();
initDate();
initImage();
this.setVisible(true);
}
private void initDate() {
int []arr1={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
Random random=new Random();
for (int i = 0; i <arr1.length ; i++) {
int len= random.nextInt(16);
int z=arr1[i];
arr1[i]=arr1[len];
arr1[len]=z;
}
int [][] date=new int[4][4];
for(int j=0;j<arr1.length;j++){
date[j/4][j%4]=arr1[j];
}
}
private void initImage() {//图片的初始化
for(int i=0;i<4;i++) {
for (int j = 0; j < 4; j++) {
int number=date[i][j];
ImageIcon icon = new ImageIcon("D:\\java\\gai\\pazzleGame\\picture\\001_" + number + ".jpg");
//管理容器
JLabel jLabel = new JLabel(icon);
//将管理容器添加到界面
this.add(jLabel);
jLabel.setBounds(105 * j, 105 * i, 105, 105);//图片位置
this.getContentPane().add(jLabel);
}
}
}
private void initJFrame(){
this.setSize(603,680);
this.setTitle("拼图游戏1.0");
this.setAlwaysOnTop(true);//界面置顶
this.setLocationRelativeTo(null);//界面居中
this.setDefaultCloseOperation(3);//关闭模式
this.setLayout(null);//取消居中放置
}
private void initJMenu(){
JMenuBar jMenuBar=new JMenuBar();//创建菜单
JMenu functionJMenu=new JMenu("功能");//创建菜单的选项
JMenu aboutJMenu=new JMenu("关于我们");
//创建选项下面的条目
JMenuItem replayIter=new JMenuItem("重新游戏");
JMenuItem reLoginItem=new JMenuItem("重新登录");
JMenuItem closeItem=new JMenuItem("关闭游戏");
JMenuItem accountItem=new JMenuItem("公众号");
//添加选项的条目
functionJMenu.add(replayIter);
functionJMenu.add(reLoginItem);
functionJMenu.add(closeItem);
aboutJMenu.add(accountItem);
//将选项添加到菜单中
jMenuBar.add(functionJMenu);
jMenuBar.add(aboutJMenu);
//设置菜单
this.setJMenuBar(jMenuBar);
}
}