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

📄 setdialog.java

📁 简单的防XP扫雷代码
💻 JAVA
字号:
package com.by.brt.mine;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 * 扫雷自定义弹出框类.
 * 
 * @author brt
 * 
 */
public class SetDialog extends JDialog implements ActionListener {

	private JLabel jl_rows, jl_cols, jl_minenum;

	private JTextField tf_rows, tf_cols, tf_minenum;

	private JButton btn_ok, btn_no;

	private Box box_label, box_tf, box_btn, box_main;

	/**
	 * 扫雷自定义弹出框类的构造方法.
	 * 
	 */
	public SetDialog() {
		super(MineClient.mf, true);
		init();
	}

	private void init() {

		box_main = Box.createHorizontalBox();

		jl_rows = new JLabel("行数:");
		jl_cols = new JLabel("列数:");
		jl_minenum = new JLabel("雷数:");
		box_label = Box.createVerticalBox();
		box_label.add(Box.createVerticalStrut(20));
		box_label.add(jl_rows);
		box_label.add(Box.createVerticalStrut(10));
		box_label.add(jl_cols);
		box_label.add(Box.createVerticalStrut(10));
		box_label.add(jl_minenum);
		box_label.add(Box.createVerticalStrut(30));
		box_main.add(Box.createHorizontalStrut(15));
		box_main.add(box_label);

		tf_rows = new JTextField(2);
		tf_rows.setText("9");
		tf_cols = new JTextField(2);
		tf_cols.setText("9");
		tf_minenum = new JTextField(3);
		tf_minenum.setText("10");
		box_tf = Box.createVerticalBox();
		box_tf.add(Box.createVerticalStrut(20));
		box_tf.add(tf_rows);
		box_tf.add(Box.createVerticalStrut(5));
		box_tf.add(tf_cols);
		box_tf.add(Box.createVerticalStrut(5));
		box_tf.add(tf_minenum);
		box_tf.add(Box.createVerticalStrut(30));
		box_main.add(Box.createHorizontalStrut(15));
		box_main.add(box_tf);

		btn_ok = new JButton("确定");
		btn_ok.addActionListener(this);
		btn_no = new JButton("取消");
		btn_no.addActionListener(this);
		box_btn = Box.createVerticalBox();
		box_btn.add(Box.createVerticalStrut(20));
		box_btn.add(btn_ok);
		box_btn.add(Box.createVerticalStrut(20));
		box_btn.add(btn_no);
		box_btn.add(Box.createVerticalStrut(30));
		box_main.add(box_btn);
		box_main.add(Box.createHorizontalStrut(15));
		box_main.add(box_btn);
		box_main.add(Box.createHorizontalStrut(15));

		this.add(box_main);
		this.setTitle("自定义雷区");
		this.setSize(192, 155);
		this.setLocationRelativeTo(MineClient.mf);
		this.setResizable(false);
		this.setVisible(true);
		this.setModal(true);
	}

	/**
	 * 弹出框中的按钮的监听方法.
	 * 
	 */
	public void actionPerformed(ActionEvent e) {

		if (e.getSource() == btn_ok) {
			MineClient.mf.setLevel(0);
			int temp = 0;
			try {
				temp = Integer.parseInt(tf_rows.getText());
			} catch (Exception e1) {
				temp = 9;
			}
			if (temp < 9) {
				temp = 9;
			} else if (temp > 30) {
				temp = 30;
			}
			MineClient.mf.setRows(temp);

			try {
				temp = Integer.parseInt(tf_cols.getText());
			} catch (Exception e1) {
				temp = 9;
			}
			if (temp < 9) {
				temp = 9;
			} else if (temp > 30) {
				temp = 30;
			}
			MineClient.mf.setCols(temp);

			try {
				temp = Integer.parseInt(tf_minenum.getText());
			} catch (Exception e1) {
				temp = 10;
			}
			if (temp < 10) {
				temp = 10;
			} else if (temp > MineClient.mf.getRows() * MineClient.mf.getCols()
					* 4 / 5) {
				temp = MineClient.mf.getRows() * MineClient.mf.getCols() * 4
						/ 5;
			}
			MineClient.mf.setMinesnum(temp);

			MineClient.mf.setLevel(0);
			MineClient.mf.setGridPanel();
		}
		dispose();
	}
}

⌨️ 快捷键说明

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