package StoneGame;
import javax.swing.*;
import java.util.Random;
public class MainStoneFrame extends JFrame {
int[][] nums = {
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,0}
};
JFrame jf=new JFrame();
public MainStoneFrame() {
CreateFrame();
UseBlocks();
jf.setVisible(true);
}
public void CreateFrame() {
jf.setSize(514,595);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jf.setTitle("石头迷阵 作者:yydslsy");
jf.setAlwaysOnTop(true);
jf.setLocationRelativeTo(null);
jf.setLayout(null);
}
public void UseBlocks() {
boolean[][] flags = {
{true,true,true,true},
{true,true,true,true},
{true,true,true,true},
{true,true,true,true}
};
Random r=new Random();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
while(true){
int n=r.nextInt();
int m=r.nextInt();
if(flags[n][m]) {
JLabel jlPicture = new JLabel(new ImageIcon("D:\\BaiduNetdiskDownload\\image\\"+nums[n][m]+".png"));
jlPicture.setBounds(50 + 100 * j, 90 + 100 * i, 100, 100);
jf.getContentPane().add(jlPicture);
flags[n][m]=false;
break;
}
}
}
}
JLabel jlBackGround=new JLabel(new ImageIcon("D:\\BaiduNetdiskDownload\\image\\background.png"));
jlBackGround.setBounds(26,30,450,484);
jf.getContentPane().add(jlBackGround);
}
}
package StoneGame;
import javax.swing.*;
public class Test {
public static void main(String[] args) {
new MainStoneFrame();
}
}
这是两个代码,我想做一个有窗口的数字华容道游戏给孙子玩,结果出错了,帮我看看,玄7关