求助,呜呜呜呜呜,玄关
  • 板块灌水区
  • 楼主yydslsy
  • 当前回复7
  • 已保存回复7
  • 发布时间2023/9/1 22:37
  • 上次更新2023/11/2 23:59:46
查看原帖
求助,呜呜呜呜呜,玄关
709534
yydslsy楼主2023/9/1 22:37
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关

2023/9/1 22:37
加载中...