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

📄 cyberthellonewgamedialog.java

📁 JCreator下开发
💻 JAVA
字号:
//“开始新游戏”对话框

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class CyberthelloNewGameDialog extends JDialog
       implements ActionListener
{
	private JRadioButton blackHumanButton;//单选框,玩家执黑子
	private JRadioButton whiteHumanButton;//单选框,玩家执白子
	private JButton okButton;
	private JButton cancelButton;
	private boolean okPressed;
	private boolean blackIsHuman;
	private boolean whiteIsHuman;
	public CyberthelloNewGameDialog(JFrame parent)//初始化
	{
		super(parent, "新游戏",	true);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		okPressed = false;
		blackIsHuman = true;
		whiteIsHuman = true;
		buildUI();
		setSize(500, 400);
	}
	public boolean okPressed()//OK被点击?
	{
		return okPressed;
	}
	public boolean blackIsHuman()//玩家执黑子?
	{
		return blackHumanButton.isSelected();
	}
	public boolean whiteIsHuman()//玩家执白子?
	{
		return whiteHumanButton.isSelected();
	}
	private void buildUI()//创建用户界面,布局
	{
		Container p = getContentPane();//创建容器p取得内容窗格
		GridBagLayout g = new GridBagLayout();//创建布局管理器
		p.setLayout(g);
		GridBagConstraints c = new GridBagConstraints(
			0, 0, 0, 1,
			0.0, 0.0,
			GridBagConstraints.CENTER, GridBagConstraints.NONE,
			new Insets(0, 0, 5, 0), 0, 0);
		//按钮布局,默认玩家执黑子
		ButtonGroup group1 = new ButtonGroup();
		c.gridx = 0;
		c.gridy = 1;
		c.gridwidth = 1;
		c.anchor = GridBagConstraints.WEST;
		blackHumanButton = new JRadioButton("玩家执黑子", true);
		group1.add(blackHumanButton);
		//blackHumanButton.addActionListener(this);
		p.add(blackHumanButton);
		g.setConstraints(blackHumanButton, c);
		ButtonGroup group2 = new ButtonGroup();
		c.gridx = 0;
		c.gridy = 6;
		c.gridwidth = 1;
		c.anchor = GridBagConstraints.WEST;
		whiteHumanButton = new JRadioButton("玩家执白子", false);
		group2.add(whiteHumanButton);
		p.add(whiteHumanButton);
		g.setConstraints(whiteHumanButton, c);
		c.gridx = 2;
		c.gridy = 12;
		c.anchor = GridBagConstraints.EAST;
		okButton = new JButton("OK");
		okButton.addActionListener(this);
		p.add(okButton);
		g.setConstraints(okButton, c);
		c.gridx = 3;
		c.gridy = 12;
		c.anchor = GridBagConstraints.WEST;
		cancelButton = new JButton("Cancel");
		cancelButton.addActionListener(this);
		p.add(cancelButton);
		g.setConstraints(cancelButton, c);
	}
	public void actionPerformed(ActionEvent e)//事件驱动,响应用户点击button
	{
		Object obj = e.getSource();

		if (obj == okButton)
		{
			okPressed = true;

			processWindowEvent(
				new WindowEvent(
					this,
					WindowEvent.WINDOW_CLOSING));
		}
		else if (obj == cancelButton)
		{
			okPressed = false;
			this.dispose();
		}
	}
}

⌨️ 快捷键说明

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