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

📄 setupgamedialog.java

📁 connectN 网络游戏。内含server and client端源程序
💻 JAVA
字号:
package client;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.LineBorder;

import utility.ConnectNConstants;

import model.ClientModel;

public class SetupGameDialog extends JDialog implements ActionListener,
		ConnectNConstants {
	private static final long serialVersionUID = 1L;
	private ClientPlayer frame;
	private ClientModel model;
	private JLabel title = new JLabel("Setup Game");
	private JLabel row = new JLabel("Row Number: ");
	private JLabel col = new JLabel("Col Number: ");
	private Choice choice1 = new Choice();
	private Choice choice2 = new Choice();
	private JRadioButton radio1 = new JRadioButton("Connect 4");
	private JRadioButton radio2 = new JRadioButton("Connect 5");
	private JRadioButton radio3 = new JRadioButton("Drop 1");
	private JRadioButton radio4 = new JRadioButton("Drop 2");
	private JPanel panel1 = new JPanel();
	private JPanel panel2 = new JPanel();
	private JButton ok = new JButton("OK");
	
	public SetupGameDialog(ClientPlayer c, ClientModel m) {
		this.frame = c;
		this.model = m;
		this.setTitle("Setup Game");
		this.setLayout(new BorderLayout());
		title.setHorizontalAlignment(JLabel.CENTER);
		title.setFont(new Font("SansSerif", Font.BOLD, 16));
		title.setBorder(new LineBorder(Color.black, 1));
		this.add(title, BorderLayout.NORTH);
		panel1.setLayout(new GridLayout(4, 2));
		choice1.add("4");
		choice1.add("5");
		choice1.add("6");
		choice1.add("7");
		choice1.add("8");
		choice1.add("9");
		choice1.add("10");
		choice2.add("4");
		choice2.add("5");
		choice2.add("6");
		choice2.add("7");
		choice2.add("8");
		choice2.add("9");
		choice2.add("10");
		panel1.add(row);
		panel1.add(choice1);
		panel1.add(col);
		panel1.add(choice2);
		ButtonGroup bg1 = new ButtonGroup();
		bg1.add(radio1);
		bg1.add(radio2);
		ButtonGroup bg2 = new ButtonGroup();
		bg2.add(radio3);
		bg2.add(radio4);
		radio1.setSelected(true);
		radio3.setSelected(true);
		radio1.addActionListener(this);
		radio2.addActionListener(this);
		radio3.addActionListener(this);
		radio4.addActionListener(this);
		panel1.add(radio1);
		panel1.add(radio2);
		panel1.add(radio3);
		panel1.add(radio4);
		this.add(panel1, BorderLayout.CENTER);
		ok.addActionListener(this);
		panel2.add(ok);
		this.add(panel2, BorderLayout.SOUTH);
		this.pack();
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		int ScreenWidth = screenSize.width;
		int ScreenHeight = screenSize.height;
		int x = (ScreenWidth - this.getWidth()) / 2;
		int y = (ScreenHeight - this.getHeight()) / 2;
		this.setLocation(x, y);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == radio1)
			model.setConnectN(ConnectNConstants.CONNECT4);
		else if (e.getSource() == radio2)
			model.setConnectN(ConnectNConstants.CONNECT5);
		else if (e.getSource() == radio3)
			model.setDropNum(ConnectNConstants.ONETURN);
		else if (e.getSource() == radio4)
			model.setDropNum(ConnectNConstants.TWOTURN);
		else if (e.getSource() == ok) {
			model.setRowNum(Integer.parseInt(choice1.getSelectedItem()));
			model.setColNum(Integer.parseInt(choice2.getSelectedItem()));
			this.dispose();
			this.frame.setVisible(true);
			this.frame.sendSetting();
		}
	}

}

⌨️ 快捷键说明

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