求java连连看游戏源代码(java 连连看)

发布时间:2022-11-09

本文目录一览:

  1. 求JAVA连连看游戏代码
  2. 用java语言编写连连看游戏
  3. 求连连看源代码

求JAVA连连看游戏代码

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class lianliankan implements ActionListener {
    JFrame mainFrame; // 主面板
    Container thisContainer;
    JPanel centerPanel, southPanel, northPanel; // 子面板
    JButton diamondsButton[][] = new JButton[6][5]; // 游戏按钮数组
    JButton exitButton, resetButton, newlyButton; // 退出,重列,重新开始按钮
    JLabel fractionLable = new JLabel("0"); // 分数标签
    JButton firstButton, secondButton; // 分别记录两次被选中的按钮
    int grid[][] = new int[8][7]; // 储存游戏按钮位置
    static boolean pressInformation = false; // 判断是否有按钮被选中
    int x0 = 0, y0 = 0, x = 0, y = 0, fristMsg = 0, secondMsg = 0, validateLV; // 游戏按钮的位置坐标
    int i, j, k, n; // 消除方法控制
    public void init() {
        mainFrame = new JFrame("JKJ连连看");
        thisContainer = mainFrame.getContentPane();
        thisContainer.setLayout(new BorderLayout());
        centerPanel = new JPanel();
        southPanel = new JPanel();
        northPanel = new JPanel();
        thisContainer.add(centerPanel, "Center");
        thisContainer.add(southPanel, "South");
        thisContainer.add(northPanel, "North");
        centerPanel.setLayout(new GridLayout(6, 5));
        for (int cols = 0; cols < 6; cols++) {
            for (int rows = 0; rows < 5; rows++) {
                diamondsButton[cols][rows] = new JButton(String.valueOf(grid[cols + 1][rows + 1]));
                diamondsButton[cols][rows].addActionListener(this);
                centerPanel.add(diamondsButton[cols][rows]);
            }
        }
        exitButton = new JButton("退出");
        exitButton.addActionListener(this);
        resetButton = new JButton("重列");
        resetButton.addActionListener(this);
        newlyButton = new JButton("再来一局");
        newlyButton.addActionListener(this);
        southPanel.add(exitButton);
        southPanel.add(resetButton);
        southPanel.add(newlyButton);
        fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));
        northPanel.add(fractionLable);
        mainFrame.setBounds(280, 100, 500, 450);
        mainFrame.setVisible(true);
    }
    public void randomBuild() {
        int randoms, cols, rows;
        for (int twins = 1; twins <= 15; twins++) {
            randoms = (int) (Math.random() * 25 + 1);
            for (int alike = 1; alike <= 2; alike++) {
                cols = (int) (Math.random() * 6 + 1);
                rows = (int) (Math.random() * 5 + 1);
                while (grid[cols][rows] != 0) {
                    cols = (int) (Math.random() * 6 + 1);
                    rows = (int) (Math.random() * 5 + 1);
                }
                this.grid[cols][rows] = randoms;
            }
        }
    }
    public void fraction() {
        fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText()) + 100));
    }
    public void reload() {
        int save[] = new int[30];
        int n = 0, cols, rows;
        int grid[][] = new int[8][7];
        for (int i = 0; i <= 6; i++) {
            for (int j = 0; j <= 5; j++) {
                if (this.grid[i][j] != 0) {
                    save[n] = this.grid[i][j];
                    n++;
                }
            }
        }
        n = n - 1;
        this.grid = grid;
        while (n >= 0) {
            cols = (int) (Math.random() * 6 + 1);
            rows = (int) (Math.random() * 5 + 1);
            while (grid[cols][rows] != 0) {
                cols = (int) (Math.random() * 6 + 1);
                rows = (int) (Math.random() * 5 + 1);
            }
            this.grid[cols][rows] = save[n];
            n--;
        }
        mainFrame.setVisible(false);
        pressInformation = false; // 这里一定要将按钮点击信息归为初始
        init();
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 5; j++) {
                if (grid[i + 1][j + 1] == 0)
                    diamondsButton[i][j].setVisible(false);
            }
        }
    }
    public void estimateEven(int placeX, int placeY, JButton bz) {
        if (pressInformation == false) {
            x = placeX;
            y = placeY;
            secondMsg = grid[x][y];
            secondButton = bz;
            pressInformation = true;
        } else {
            x0 = x;
            y0 = y;
            fristMsg = secondMsg;
            firstButton = secondButton;
            x = placeX;
            y = placeY;
            secondMsg = grid[x][y];
            secondButton = bz;
            if (fristMsg == secondMsg && secondButton != firstButton) {
                xiao();
            }
        }
    }
    public void estimateEven(int placeX, int placeY, JButton bz) {
        if (pressInformation == false) {
            x = placeX;
            y = placeY;
            secondMsg = grid[x][y];
            secondButton = bz;
            pressInformation = true;
        } else {
            x0 = x;
            y0 = y;
            fristMsg = secondMsg;
            firstButton = secondButton;
            x = placeX;
            y = placeY;
            secondMsg = grid[x][y];
            secondButton = bz;
            if (fristMsg == secondMsg && secondButton != firstButton) {
                xiao();
            }
        }
    }
    public void xiao() { // 相同的情况下能不能消去。仔细分析,不一条条注释
        if ((x0 == x && (y0 == y + 1 || y0 == y - 1)) || ((x0 == x + 1 || x0 == x - 1) && (y0 == y))) { // 判断是否相邻
            remove();
        } else {
            for (j = 0; j < 7; j++) {
                if (grid[x0][j] == 0) { // 判断第一个按钮同行哪个按钮为空
                    if (y < j) { // 如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边
                        for (i = y - 1; i >= j; i--) { // 判断第二按钮左侧直到第一按钮中间有没有按钮
                            if (grid[x][i] != 0) {
                                k = 0;
                                break;
                            } else {
                                k = 1;
                            } // K=1说明通过了第一次验证
                        }
                        if (k == 1) {
                            linePassOne();
                        }
                    }
                    if (y > j) { // 如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边
                        for (i = y + 1; i <= j; i++) { // 判断第二按钮左侧直到第一按钮中间有没有按钮
                            if (grid[x][i] != 0) {
                                k = 0;
                                break;
                            } else {
                                k = 1;
                            }
                        }
                        if (k == 1) {
                            linePassOne();
                        }
                    }
                    if (y == j) {
                        linePassOne();
                    }
                }
            }
            if (k == 2) {
                if (x0 == x) {
                    remove();
                }
                if (x0 < x) {
                    for (n = x0; n <= x - 1; n++) {
                        if (grid[n][j] != 0) {
                            k = 0;
                            break;
                        }
                        if (grid[n][j] == 0 && n == x - 1) {
                            remove();
                        }
                    }
                }
                if (x0 > x) {
                    for (n = x0; n <= x + 1; n--) {
                        if (grid[n][j] != 0) {
                            k = 0;
                            break;
                        }
                        if (grid[n][j] == 0 && n == x + 1) {
                            remove();
                        }
                    }
                }
            }
        }
        for (i = 0; i < 8; i++) { // 列
            if (grid[i][y0] == 0) {
                if (x < i) {
                    for (j = x - 1; j >= i; j--) {
                        if (grid[j][y] != 0) {
                            k = 0;
                            break;
                        } else {
                            k = 1;
                        }
                    }
                    if (k == 1) {
                        rowPassOne();
                    }
                }
                if (x > i) {
                    for (j = x + 1; j <= i; j++) {
                        if (grid[j][y] != 0) {
                            k = 0;
                            break;
                        } else {
                            k = 1;
                        }
                    }
                    if (k == 1) {
                        rowPassOne();
                    }
                }
                if (x == i) {
                    rowPassOne();
                }
            }
        }
        if (k == 2) {
            if (y0 == y) {
                remove();
            }
            if (y0 < y) {
                for (n = y0; n <= y - 1; n++) {
                    if (grid[i][n] != 0) {
                        k = 0;
                        break;
                    }
                    if (grid[i][n] == 0 && n == y - 1) {
                        remove();
                    }
                }
            }
            if (y0 > y) {
                for (n = y0; n <= y + 1; n--) {
                    if (grid[i][n] != 0) {
                        k = 0;
                        break;
                    }
                    if (grid[i][n] == 0 && n == y + 1) {
                        remove();
                    }
                }
            }
        }
    }
    public void linePassOne() {
        if (y0 < j) { // 第一按钮同行空按钮在左边
            for (i = y0 - 1; i >= j; i--) { // 判断第一按钮同左侧空按钮之间有没按钮
                if (grid[x0][i] != 0) {
                    k = 0;
                    break;
                } else {
                    k = 2;
                } // K=2说明通过了第二次验证
            }
        }
        if (y0 > j) { // 第一按钮同行空按钮在与第二按钮之间
            for (i = y0 + 1; i <= j; i++) {
                if (grid[x0][i] != 0) {
                    k = 0;
                    break;
                } else {
                    k = 2;
                }
            }
        }
    }
    public void rowPassOne() {
        if (x0 < i) {
            for (j = x0 - 1; j >= i; j--) {
                if (grid[j][y0] != 0) {
                    k = 0;
                    break;
                } else {
                    k = 2;
                }
            }
        }
        if (x0 > i) {
            for (j = x0 + 1; j <= i; j++) {
                if (grid[j][y0] != 0) {
                    k = 0;
                    break;
                } else {
                    k = 2;
                }
            }
        }
    }
    public void remove() {
        firstButton.setVisible(false);
        secondButton.setVisible(false);
        fraction();
        pressInformation = false;
        k = 0;
        grid[x0][y0] = 0;
        grid[x][y] = 0;
    }
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == newlyButton) {
            int grid[][] = new int[8][7];
            this.grid = grid;
            randomBuild();
            mainFrame.setVisible(false);
            pressInformation = false;
            init();
        }
        if (e.getSource() == exitButton)
            System.exit(0);
        if (e.getSource() == resetButton)
            reload();
        for (int cols = 0; cols < 6; cols++) {
            for (int rows = 0; rows < 5; rows++) {
                if (e.getSource() == diamondsButton[cols][rows])
                    estimateEven(cols + 1, rows + 1, diamondsButton[cols][rows]);
            }
        }
    }
    public static void main(String[] args) {
        lianliankan llk = new lianliankan();
        llk.randomBuild();
        llk.init();
    }
}

用java语言编写连连看游戏

我以前自己写一个玩的。没有把你要求的功能全部实现,不过你看了后可以改一下就好了。参考一下吧,我给了注解:

package mybase.programe;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class LianLianKan implements ActionListener {
    JFrame mainFrame; // 主面板
    Container thisContainer;
    JPanel centerPanel, southPanel, northPanel; // 子面板
    JButton diamondsButton[][] = new JButton[6][5]; // 游戏按钮数组
    JButton exitButton, resetButton, newlyButton; // 退出,重列,重新开始按钮
    JLabel fractionLable = new JLabel("0"); // 分数标签
    JButton firstButton, secondButton; // 分别记录两次被选中的按钮
    int grid[][] = new int[8][7]; // 储存游戏按钮位置
    static boolean pressInformation = false; // 判断是否有按钮被选中
    int x0 = 0, y0 = 0, x = 0, y = 0, fristMsg = 0, secondMsg = 0, validateLV; // 游戏按钮的位置坐标
    int i, j, k, n; // 消除方法控制
    public void init() {
        mainFrame = new JFrame("JKJ连连看");
        thisContainer = mainFrame.getContentPane();
        thisContainer.setLayout(new BorderLayout());
        centerPanel = new JPanel();
        southPanel = new JPanel();
        northPanel = new JPanel();
        thisContainer.add(centerPanel, "Center");
        thisContainer.add(southPanel, "South");
        thisContainer.add(northPanel, "North");
        centerPanel.setLayout(new GridLayout(6, 5));
        for (int cols = 0; cols < 6; cols++) {
            for (int rows = 0; rows < 5; rows++) {
                diamondsButton[cols][rows] = new JButton(String.valueOf(grid[cols + 1][rows + 1]));
                diamondsButton[cols][rows].addActionListener(this);
                centerPanel.add(diamondsButton[cols][rows]);
            }
        }
        exitButton = new JButton("退出");
        exitButton.addActionListener(this);
        resetButton = new JButton("重列");
        resetButton.addActionListener(this);
        newlyButton = new JButton("再来一局");
        newlyButton.addActionListener(this);
        southPanel.add(exitButton);
        southPanel.add(resetButton);
        southPanel.add(newlyButton);
        fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));
        northPanel.add(fractionLable);
        mainFrame.setBounds(280, 100, 500, 450);
        mainFrame.setVisible(true);
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public void randomBuild() {
        int randoms, cols, rows;
        for (int twins = 1; twins <= 15; twins++) { // 一共15对button,30个
            randoms = (int) (Math.random() * 25 + 1); // button上的数字
            for (int alike = 1; alike <= 2; alike++) {
                cols = (int) (Math.random() * 6 + 1);
                rows = (int) (Math.random() * 5 + 1);
                while (grid[cols][rows] != 0) { // 等于0说明这个空格有了button
                    cols = (int) (Math.random() * 6 + 1);
                    rows = (int) (Math.random() * 5 + 1);
                }
                this.grid[cols][rows] = randoms;
            }
        }
    }
    public void fraction() {
        fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText()) + 100));
    }
    public void reload() {
        int save[] = new int[30];
        int n = 0, cols, rows;
        int grid[][] = new int[8][7];
        for (int i = 0; i <= 6; i++) {
            for (int j = 0; j <= 5; j++) {
                if (this.grid[i][j] != 0) {
                    save[n] = this.grid[i][j]; // 记下每个button的数字
                    n++; // 有几个没有消去的button
                }
            }
        }
        n = n - 1;
        this.grid = grid;
        while (n >= 0) { // 把没有消去的button重新放一次
            cols = (int) (Math.random() * 6 + 1);
            rows = (int) (Math.random() * 5 + 1);
            while (grid[cols][rows] != 0) {
                cols = (int) (Math.random() * 6 + 1);
                rows = (int) (Math.random() * 5 + 1);
            }
            this.grid[cols][rows] = save[n];
            n--;
        }
        mainFrame.setVisible(false);
        pressInformation = false; // 这里一定要将按钮点击信息归为初始
        init();
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 5; j++) {
                if (grid[i + 1][j + 1] == 0)
                    diamondsButton[i][j].setVisible(false);
            }
        }
    }
    public void estimateEven(int placeX, int placeY, JButton bz) {
        if (pressInformation == false) {
            x = placeX;
            y = placeY;
            secondMsg = grid[x][y];
            secondButton = bz;
            pressInformation = true;
        } else {
            x0 = x;
            y0 = y;
            fristMsg = secondMsg;
            firstButton = secondButton;
            x = placeX;
            y = placeY;
            secondMsg = grid[x][y];
            secondButton = bz;
            if (fristMsg == secondMsg && secondButton != firstButton) {
                xiao();
            }
        }
    }
    public void xiao() { // 相同的情况下能不能消去。仔细分析,不一条条注释
        if ((x0 == x && (y0 == y + 1 || y0 == y - 1)) || ((x0 == x + 1 || x0 == x - 1) && (y0 == y))) { // 判断是否相邻
            remove();
        } else {
            for (j = 0; j < 7; j++) {
                if (grid[x0][j] == 0) { // 判断和第一个按钮同行的哪个按钮为空
                    if (y < j) { // 第二个按钮在空按钮右边
                        for (i = y - 1; i >= j; i--) { // 检测从第二个按钮横向左边到空格所在列为止是否全是空格
                            if (grid[x][i] != 0) {
                                k = 0;
                                break; // 存在非空格的就退出,这一退出就不可能k==2了,所以就会到下而215行出同理的判断列
                            } else {
                                k = 1;
                            } // K=1说明全是空格通过了第一次验证,也就是从第二个按钮横向左边到空格所在列为止全是空格
                        }
                        if (k == 1) {
                            linePassOne(); // 进入第二次验证,也就是从第一个按钮到它同行的空格之间的空格判断
                        }
                    }
                    if (y > j) { // 第二个按钮在空按钮左边
                        for (i = y + 1; i <= j; i++) { // 检测从第二个按钮横向右边到空格所在列为止是否全是空格
                            if (grid[x][i] != 0) {
                                k = 0;
                                break;
                            } else {
                                k = 1;
                            }
                        }
                        if (k == 1) {
                            linePassOne();
                        }
                    }
                    if (y == j) { // 第二个按钮和空按钮同列
                        linePassOne();
                    }
                }
                if (k == 2) {
                    if (x0 == x) { // 第一,二按钮在同行
                        remove();
                    }
                    if (x0 < x) { // 第一按钮在第二按钮下边
                        for (n = x0; n <= x - 1; n++) { // 从空按钮竖向到第二个按钮所在行是否有按钮
                            if (grid[n][j] != 0) {
                                k = 0;
                                break;
                            }
                            if (grid[n][j] == 0 && n == x - 1) { // 没有按钮,说明这条路经就通了
                                remove();
                            }
                        }
                    }
                    if (x0 > x) { // 第一按钮在第二按钮上边
                        for (n = x0; n <= x + 1; n--) {
                            if (grid[n][j] != 0) {
                                k = 0;
                                break;
                            }
                            if (grid[n][j] == 0 && n == x + 1) {
                                remove();
                            }
                        }
                    }
                }
            }
            for (i = 0; i < 8; i++) { // 列
                if (grid[i][y0] == 0) { // 判断和第一个按钮同列的哪个按钮为空
                    if (x < i) { // 第二个按钮在这个空按钮的下面
                        for (j = x - 1; j >= i; j--) {
                            if (grid[j][y] != 0) {
                                k = 0;
                                break;
                            } else {
                                k = 1;
                            }
                        }
                        if (k == 1) {
                            rowPassOne();
                        }
                    }
                    if (x > i) { // 第二个按钮在这个空按钮的上面
                        for (j = x + 1; j <= i; j++) {
                            if (grid[j][y] != 0) {
                                k = 0;
                                break;
                            } else {
                                k = 1;
                            }
                        }
                        if (k == 1) {
                            rowPassOne();
                        }
                    }
                    if (x == i) { // 第二个按钮与这个空按钮同行
                        rowPassOne();
                    }
                }
                if (k == 2) {
                    if (y0 == y) { // 第二个按钮与第一个按钮同列
                        remove();
                    }
                    if (y0 < y) { // 第二个按钮在第一个按钮右边
                        for (n = y0; n <= y - 1; n++) {
                            if (grid[i][n] != 0) {
                                k = 0;
                                break;
                            }
                            if (grid[i][n] == 0 && n == y - 1) {
                                remove();
                            }
                        }
                    }
                    if (y0 > y) { // 第二个按钮在第一个按钮左边
                        for (n = y0; n <= y + 1; n--) {
                            if (grid[i][n] != 0) {
                                k = 0;
                                break;
                            }
                            if (grid[i][n] == 0 && n == y + 1) {
                                remove();
                            }
                        }
                    }
                }
            }
        }
    }
    public void linePassOne() {
        if (y0 < j) { // 第一按钮同行空按钮在左边
            for (i = y0 - 1; i >= j; i--) { // 判断第一按钮同左侧空按钮之间有没按钮
                if (grid[x0][i] != 0) {
                    k = 0;
                    break;
                } else {
                    k = 2;
                } // K=2说明通过了第二次验证
            }
        }
        if (y0 > j) { // 第一按钮同行空按钮在右边
            for (i = y0 + 1; i <= j; i++) {
                if (grid[x0][i] != 0) {
                    k = 0;
                    break;
                } else {
                    k = 2;
                }
            }
        }
    }
    public void rowPassOne() {
        if (x0 < i) { // 第一个按钮在与它同列的那个空按钮下面
            for (j = x0 - 1; j >= i; j--) {
                if (grid[j][y0] != 0) {
                    k = 0;
                    break;
                } else {
                    k = 2;
                }
            }
        }
        if (x0 > i) { // 第一个按钮在与它同列的那个空按钮上面
            for (j = x0 + 1; j <= i; j++) {
                if (grid[j][y0] != 0) {
                    k = 0;
                    break;
                } else {
                    k = 2;
                }
            }
        }
    }
    public void remove() {
        firstButton.setVisible(false);
        secondButton.setVisible(false);
        fraction();
        pressInformation = false;
        k = 0;
        grid[x0][y0] = 0;
        grid[x][y] = 0;
    }
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == newlyButton) {
            int grid[][] = new int[8][7];
            this.grid = grid;
            randomBuild();
            mainFrame.setVisible(false);
            pressInformation = false;
            init();
        }
        if (e.getSource() == exitButton)
            System.exit(0);
        if (e.getSource() == resetButton)
            reload();
        for (int cols = 0; cols < 6; cols++) {
            for (int rows = 0; rows < 5; rows++) {
                if (e.getSource() == diamondsButton[cols][rows])
                    estimateEven(cols + 1, rows + 1, diamondsButton[cols][rows]);
            }
        }
    }
    public static void main(String[] args) {
        LianLianKan llk = new LianLianKan();
        llk.randomBuild();
        llk.init();
    }
}

求连连看源代码

连连看的代码(基本算法)加了部分注释

import java.awt.*;
import java.awt.event.*;
public class lianliankan implements ActionListener {
    static String s = "no"; // 用来纪录点击按钮的信息
    int x0 = 0, y0 = 0, x = 0, y = 0, n1 = 0, n2 = 0; // 用来纪录按钮的位置信息
    Frame f, f1;
    Button b1, b2, b3, b4, b5, b6, b7, b8, b9, b10; // 用比较笨的方法添加了
    Button b11, b12, b13, b14, b15, b16, b17, b18; // 30个按钮来实现游戏界面
    Button b19, b20, b21, b22, b23, b24, b25; // 可以用数组实现,这是本人
    Button b26, b27, b28, b29, b30, bc; // 学java时,入门的联系,所以
    Button b, ba, br, bt1, bt2; // 有些东西很业余!!嘻嘻
    Panel p1, p2, p3;
    TextField t; // 用来显示一些随机信息,方法是下面的guli().
    Label l;
    int d[][] = { // 用来和界面的按钮建立映射关系
        { 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0 }
    };
    public static void main(String[] args) {
        lianliankan t = new lianliankan();
        t.suiji();
        t.go();
    }
    public void actionPerformed(ActionEvent e) // 再来一次按钮的响应事件。
    {
        int d[][] = {
            { 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0 }
        };
        this.d = d;
        suiji();
        f.setVisible(false);
        f1.setVisible(false);
        s = "no";
        go();
    }
    public void go() // 初始化界面
    {
        l = new Label("亲爱的玩家,");
        f = new Frame("连连看");
        t = new TextField();
        p2 = new Panel();
        p1 = new Panel();
        p3 = new Panel();
        bc = new Button("退出");
        br = new Button("重列");
        b = new Button();
        b1 = new Button(String.valueOf(d[1][1]));
        b2 = new Button(String.valueOf(d[1][2]));
        b3 = new Button(String.valueOf(d[1][3]));
        b4 = new Button(String.valueOf(d[1][4]));
        b5 = new Button(String.valueOf(d[1][5]));
        b6 = new Button(String.valueOf(d[2][1]));
        b7 = new Button(String.valueOf(d[2][2]));
        b8 = new Button(String.valueOf(d[2][3]));
        b9 = new Button(String.valueOf(d[2][4]));
        b10 = new Button(String.valueOf(d[2][5]));
        b11 = new Button(String.valueOf(d[3][1]));
        b12 = new Button(String.valueOf(d[3][2]));
        b13 = new Button(String.valueOf(d[3][3]));
        b14 = new Button(String.valueOf(d[3][4]));
        b15 = new Button(String.valueOf(d[3][5]));
        b16 = new Button(String.valueOf(d[4][1]));
        b17 = new Button(String.valueOf(d[4][2]));
        b18 = new Button(String.valueOf(d[4][3]));
        b19 = new Button(String.valueOf(d[4][4]));
        b20 = new Button(String.valueOf(d[4][5]));
        b21 = new Button(String.valueOf(d[5][1]));
        b22 = new Button(String.valueOf(d[5][2]));
        b23 = new Button(String.valueOf(d[5][3]));
        b24 = new Button(String.valueOf(d[5][4]));
        b25 = new Button(String.valueOf(d[5][5]));
        b26 = new Button(String.valueOf(d[6][1]));
        b27 = new Button(String.valueOf(d[6][2]));
        b28 = new Button(String.valueOf(d[6][3]));
        b29 = new Button(String.valueOf(d[6][4]));
        b30 = new Button(String.valueOf(d[6][5]));
        p3.setLayout(null);
        p1.setSize(250, 300);
        p2.setSize(100, 40);
        p3.setSize(300, 30);
        t.setSize(60, 30);
        l.setSize(70, 30);
        p1.setLayout(new GridLayout(6, 5));
        p1.setBackground(Color.pink);
        p1.setLocation(100, 100);
        p2.setLocation(0, 400);
        p3.setLocation(50, 50);
        t.setLocation(230, 2);
        l.setLocation(150, 2);
        bc.setLocation(0, 40);
        br.setLocation(0, 100);
        f.add(p1);
        f.add(p2);
        f.add(p3);
        p3.add(l);
        p3.add(t);
        p2.add(bc);
        p2.add(br);
        p1.add(b1);
        p1.add(b2);
        p1.add(b3);
        p1.add(b4);
        p1.add(b5);
        p1.add(b6);
        p1.add(b7);
        p1.add(b8);
        p1.add(b9);
        p1.add(b10);
        p1.add(b11);
        p1.add(b12);
        p1.add(b13);
        p1.add(b14);
        p1.add(b15);
        p1.add(b16);
        p1.add(b17);
        p1.add(b18);
        p1.add(b19);
        p1.add(b20);
        p1.add(b21);
        p1.add(b22);
        p1.add(b23);
        p1.add(b24);
        p1.add(b25);
        p1.add(b26);
        p1.add(b27);
        p1.add(b28);
        p1.add(b29);
        p1.add(b30);
        f.pack();
        f.setBounds(280, 100, 500, 450);
        f.setResizable(false);
        f.setVisible(true);
        bc.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                ex();
            }
        });
        br.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                chonglie();
            }
        });
        b1.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(1, 1, b1);
            }
        });
        b2.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(1, 2, b2);
            }
        });
        b3.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(1, 3, b3);
            }
        });
        b4.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(1, 4, b4);
            }
        });
        b5.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(1, 5, b5);
            }
        });
        b6.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(2, 1, b6);
            }
        });
        b7.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(2, 2, b7);
            }
        });
        b8.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(2, 3, b8);
            }
        });
        b9.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(2, 4, b9);
            }
        });
        b10.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(2, 5, b10);
            }
        });
        b11.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(3, 1, b11);
            }
        });
        b12.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(3, 2, b12);
            }
        });
        b13.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(3, 3, b13);
            }
        });
        b14.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(3, 4, b14);
            }
        });
        b15.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(3, 5, b15);
            }
        });
        b16.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(4, 1, b16);
            }
        });
        b17.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                wei(4, 2, b17);
            }
        });
        b