⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customdialog.java

📁 一个完全实现的扫雷程序
💻 JAVA
字号:
package mine.view;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import mine.*;
public class CustomDialog
    extends JDialog {
    JPanel panel1 = new JPanel();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JTextField HeightF = new JTextField();
    JTextField MineF = new JTextField();
    JTextField WidthF = new JTextField();
    JButton confirmButton = new JButton();
    JButton cancelButton = new JButton();
    GameConfigure gameconfigure = GameConfigure.getInstance();

    public CustomDialog(Frame frame) {
        super(frame, "自定义设置", true);
        try {
            jbInit();
            this.setSize(300, 200);
            this.setBounds( (int) frame.getX() + 20,
                           (int) frame.getY() + 75, 300, 200);

        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public CustomDialog() {

    }

    private void jbInit() throws Exception {
        panel1.setLayout(null);
        jLabel1.setText("高度");
        jLabel1.setBounds(new Rectangle(20, 20, 43, 21));
        jLabel2.setBounds(new Rectangle(20, 49, 41, 21));
        jLabel2.setText("宽度");
        jLabel3.setBounds(new Rectangle(20, 76, 41, 21));
        jLabel3.setText("雷数");
        HeightF.setText(String.valueOf(gameconfigure.getYy()));
        HeightF.setBounds(new Rectangle(62, 22, 39, 18));
        MineF.setText(String.valueOf(gameconfigure.getMineNumber()));
        MineF.setBounds(new Rectangle(62, 78, 39, 18));
        WidthF.setText(String.valueOf(gameconfigure.getXx()));
        WidthF.setBounds(new Rectangle(62, 50, 39, 18));
        confirmButton.setBounds(new Rectangle(119, 27, 62, 24));
        confirmButton.setText("确定");
        confirmButton.addActionListener(new
                                        CustomDialog_confirmButton_actionAdapter(this));
        cancelButton.setText("取消");
        cancelButton.addActionListener(new
                                       CustomDialog_cancelButton_actionAdapter(this));
        cancelButton.setBounds(new Rectangle(121, 71, 62, 24));
        getContentPane().add(panel1);
        panel1.add(jLabel3, null);
        panel1.add(jLabel2, null);
        panel1.add(jLabel1, null);
        panel1.add(cancelButton, null);
        panel1.add(confirmButton, null);
        panel1.add(MineF, null);
        panel1.add(WidthF, null);
        panel1.add(HeightF, null);

        int prexx = gameconfigure.getXx();
        int preyy = gameconfigure.getYy();
        int premine = gameconfigure.getMineNumber();

        gameconfigure.setLevel(0);
        gameconfigure.setXx(prexx);
        gameconfigure.setYy(preyy);
        gameconfigure.setMineNumber(premine);
    }

    public static boolean numberCheck(String number) {
        if (number == null) {
            return false;
        }
        return number.matches("[0-9]+");
    }

    void confirmButton_actionPerformed(ActionEvent e) {
        String xxS = WidthF.getText();
        String yyS = HeightF.getText();
        String mineS = MineF.getText();
        if (xxS.length() < 4 && yyS.length() < 4 && mineS.length() < 4) {
            if (numberCheck(xxS) && numberCheck(yyS) && numberCheck(mineS)) {
                int xx = Integer.parseInt(xxS);
                int yy = Integer.parseInt(yyS);
                int mine = Integer.parseInt(mineS);
                if (xx > 0 && xx < 36 && yy > 0 && yy < 36 && xx * yy > mine) {
                    gameconfigure.setXx(xx);
                    gameconfigure.setYy(yy);
                    gameconfigure.setMineNumber(mine);
                }
            }
        }
        this.dispose();

    }

    void cancelButton_actionPerformed(ActionEvent e) {
        this.dispose();
    }
}


class CustomDialog_confirmButton_actionAdapter
    implements java.awt.event.ActionListener {
    CustomDialog adaptee;

    CustomDialog_confirmButton_actionAdapter(CustomDialog adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.confirmButton_actionPerformed(e);
    }
}


class CustomDialog_cancelButton_actionAdapter
    implements java.awt.event.ActionListener {
    CustomDialog adaptee;

    CustomDialog_cancelButton_actionAdapter(CustomDialog adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.cancelButton_actionPerformed(e);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -