/**
*
* @author 陆垚
*/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.util.*;
import java.awt.Font;
public class Main{
public static void main(String args[]){
BlackAndWhiteDesign b = new BlackAndWhiteDesign();
}
}
class BlackAndWhiteDesign extends Frame implements Runnable{
Go Background = new Go();
boolean stepColor = true;
int PORT;
Socket sendSocket;//主动连接Socket
PrintWriter writer;//用来发送message
boolean stopFlag;
boolean isInitiative;
Point messagePoint;
Panel panel1 = new Panel();
Panel panel2 = new Panel();
Panel panel3 = new Panel();
CheckboxGroup checkboxGroup1 = new CheckboxGroup();
Checkbox checkbox1 = new Checkbox();
Checkbox checkbox2 = new Checkbox();
Label label1 = new Label();
TextField textField1 = new TextField(10);
Panel PtextField1 = new Panel();
Button button1 = new Button();
Label label2 = new Label();
Choice choice1 = new Choice();
Button button2 = new Button();
Button button3 = new Button();
BorderLayout borderLayout3 = new BorderLayout();
Panel panel4 = new Panel();
Panel panel4_1 = new Panel();
Panel panel4_2 = new Panel();
Panel panel4_3 = new Panel();
Label label3 = new Label("黑棋");
Label label4 = new Label("白棋");
JTextArea BlackNumber = new JTextArea("02"); //定义并初始化黑棋计数板
JTextArea WhiteNumber = new JTextArea("02"); //定义并初始化白棋计数板
BlackAndWhiteDesign(){
try
{
bwInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void bwInit() throws Exception{
this.setTitle("网络黑白棋Beta1.0 作者:陆垚");
new Thread(this).start();//启动监听线程
this.PORT = 1976;
this.isInitiative = false;//是否主动连接
this.stopFlag = false;//是否继续监听的标志
this.messagePoint = new Point();
choice1.setBackground(new Color(236, 190, 98));
this.choice1.addItem("黑");
this.choice1.addItem("白");
this.setBackground(new Color(236, 190, 98));
this.setSize(580,565);
this.setResizable(false);
this.setVisible(true);
checkbox1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
checkbox1_mouseClicked(e);
}
});
panel1.setLayout(new BorderLayout());
checkbox1.setCheckboxGroup(checkboxGroup1);
checkbox1.setLabel("单机");
checkbox2.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
checkbox2_mouseClicked(e);
}
});
checkbox2.setCheckboxGroup(checkboxGroup1);
checkbox2.setLabel("联机");
label1.setText("对方地址");
button1.setBackground(new Color(236, 190, 98));
button1.setLabel("连接");
button1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
button1_actionPerformed(e);
}
});
label2.setText(" ");
button2.setBackground(new Color(236, 190, 98));
button2.setLabel("开始");
button2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
button2_actionPerformed(e);
}
});
button3.setBackground(new Color(236, 190, 98));
button3.setLabel("重新开始");
this.button3.setEnabled(false);
button3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
button3_actionPerformed(e);
}
});
Background.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
Background_mouseClicked(e);
}
});
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
this_windowClosing(e);
}
});
panel3.setLayout(new GridLayout(9, 1));
panel3.setBackground(new Color(236, 190, 98));
panel3.add(checkbox1);
panel3.add(checkbox2);
panel3.add(label1);
PtextField1.add(textField1);
panel3.add(PtextField1);
panel3.add(choice1);
panel3.add(button1);
panel3.add(button2);
panel3.add(button3);
panel3.add(label2);
panel4.setLayout(new GridLayout(1, 3));
label3.setFont(new Font("h",15,30));
panel4_1.add(label3);
BlackNumber.setFont(new Font("h",15,30));
BlackNumber.setEditable(false);
panel4_1.add(BlackNumber);
label4.setFont(new Font("h",15,30));
panel4_2.add(label4);
WhiteNumber.setFont(new Font("h",15,30));
WhiteNumber.setEditable(false);
panel4_2.add(WhiteNumber);
panel4.add(panel4_1);
panel4.add(panel4_2);
panel4.add(panel4_3);
this.panel1.add(this.Background,BorderLayout.CENTER);
this.panel1.add(panel3, BorderLayout.EAST);
this.panel1.add(panel4, BorderLayout.SOUTH);
this.add(panel1, BorderLayout.CENTER);
this.disableLink();//废掉控件
this.checkboxGroup1.setSelectedCheckbox(this.checkbox1);
this.centerWindow();
this.Background.setEnabled(false);
this.setVisible(true);
}
void checkbox1_mouseClicked(MouseEvent e)
{
this.button2.setEnabled(true);
this.disableLink();
}
//disable联机时用的控件
void disableLink()
{
this.textField1.setBackground(new Color(236, 190, 98));
this.textField1.setEnabled(false);
this.choice1.setEnabled(false);
this.button1.setEnabled(false);
}
void checkbox2_mouseClicked(MouseEvent e)
{
this.enableLink();
}
void enableLink()
{
this.textField1.setBackground(Color.white);
this.textField1.setEnabled(true);
this.choice1.setEnabled(true);
this.button1.setEnabled(true);
this.button2.setEnabled(false);
}
void button1_actionPerformed(ActionEvent e)
{
this.stopFlag = false;
this.goToLink(this.textField1.getText().trim(),this.PORT);
this.button2.setEnabled(true);
}
//开始
void button2_actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("开始"))
{
this.stopFlag = false;
this.disableLink();
this.button3.setEnabled(true);
this.checkbox1.setEnabled(false);
this.checkbox2.setEnabled(false);
this.button2.setLabel("退出");
if(this.isSingle())
this.Background.setEnabled(true);
else//联机版时
{
if(this.choice1.getSelectedItem().equals("黑"))
{
this.writer.println("start_black");
}
else this.writer.println("start_white");
}
this.paintMyColor();//表明颜色
}
else if(e.getActionCommand().equals("退出"))
{
this.dispose();
System.exit(0);
}
}
//判断类型
boolean isSingle()
{
return this.checkbox1.getState();
没有合适的资源?快使用搜索试试~ 我知道了~
JAVA版网络黑白棋
共13个文件
class:12个
java:1个
4星 · 超过85%的资源 需积分: 9 101 下载量 146 浏览量
2009-07-09
20:02:53
上传
评论
收藏 21KB RAR 举报
温馨提示
黑白棋,也叫翻转棋,类似于棋盘游戏“奥赛罗 (Othello)”,是一种得分会戏剧性变化并且需要长时 间思考的策略性游戏。 本程序通过JAVA实现了点对点网络对战黑白棋。
资源推荐
资源详情
资源评论
收起资源包目录
JAVA版网络黑白棋.rar (13个子文件)
源代码
BlackAndWhiteDesign$7.class 527B
Go.class 7KB
BlackAndWhiteDesign$5.class 559B
BlackAndWhiteDesign$6.class 529B
BlackAndWhiteDesign$1.class 528B
Main.java 40KB
BlackAndWhiteDesign.class 13KB
BlackAndWhiteDesign$3.class 559B
Main.class 295B
Listen.class 996B
One.class 640B
BlackAndWhiteDesign$2.class 528B
BlackAndWhiteDesign$4.class 559B
共 13 条
- 1
资源评论
- vcx152016-03-04不知道怎么用
- jimoyiyanhua2013-03-30貌似用不了,可能是网络的设置问题
- hdh2789201962014-03-21没有调试出来啊,正在研究中。。。
- gemini_lucky2013-03-18用不了……
- abcfmj2012-06-23代码看起来很复杂,不能运行,也没有调试成功...
klldmofashi
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功