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

📄 breakrecorddialog.java

📁 eclipse下面实现的java扫雷游戏
💻 JAVA
字号:
/*
 * Created on 2005-5-23
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package view;

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

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * @author mqqqvpppm
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class BreakRecordDialog {

	public BreakRecordDialog(JFrame parent, int type) {
		super();
		initialization(parent, type);
	}

	public boolean show(int time) {
		ok = false;
		if (type == BREAK) {
			label.setText(time
					+ " Second! You Break the Record! Please Input Your Name:");
		} else {
			label.setText( time + " Second!  You Win it!");
		}
		dialog.show();
		return ok;
	}

	public String getUserName() {
		if (ok)
			return textField.getText();
		return null;
	}

	private void initialization(JFrame parent, int type) {
		dialog = new JDialog(parent, true);
		ok = false;
		this.type = type;

		okBtn = new JButton("ok");
		label = new JLabel();

		okBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ok = true;
				dialog.setVisible(false);
			}
		});

		Font font = new Font("Monospaced", Font.PLAIN, 12);
		okBtn.setFont(font);
		label.setFont(font);
		if (type == BREAK) {
			dialog.setTitle("Break Record!");
			textField = new JTextField();
			cancelBtn = new JButton("cancel");
			cancelBtn.setFont(font);
			textField.setFont(font);
			cancelBtn.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					dialog.setVisible(false);
				}
			});
		} else {
			dialog.setTitle("You Win!");
		}

		dialog.setResizable(false);
		if (type == BREAK) {
			dialog.setBounds(parent.getLocation().x + 50,
					parent.getLocation().y + 50, 400, 160);
			okBtn.setBounds(210, 85, 70, 23);
			cancelBtn.setBounds(300, 85, 70, 23);
			textField.setBounds(20, 50, 350, 23);
			label.setBounds(20, 20, 350, 23);

			JPanel panel = new JPanel();
			panel.setLayout(null);
			panel.add(okBtn);
			panel.add(cancelBtn);
			panel.add(textField);
			panel.add(label);
			dialog.setContentPane(panel);
		} else {
			dialog.setBounds(parent.getLocation().x + 50,
					parent.getLocation().y + 50, 200, 120);
			okBtn.setBounds(65, 50, 70, 23);
			//			cancelBtn.setBounds(300, 45, 70, 23);
			//			textField.setBounds(20, 50, 350, 23);
			label.setBounds(20, 20, 350, 23);

			JPanel panel = new JPanel();
			panel.setLayout(null);
			panel.add(okBtn);
			//			panel.add(cancelBtn);
			//			panel.add(textField);
			panel.add(label);
			dialog.setContentPane(panel);
		}
	}

	public static final int BREAK = 0;

	public static final int JUST_WIN = 1;

	private int type;

	private boolean ok;

	private JDialog dialog;

	private JLabel label;

	private JButton okBtn;

	private JButton cancelBtn;

	private JTextField textField;
}

⌨️ 快捷键说明

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