提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
架构图
部分代码
1、窗口的搭建
public class ClientWindow extends JFrame{
public static ClientChessBoard qipan;
ClientChat talk = new ClientChat();;
public ClientWindow(){
qipan = new ClientChessBoard();
this.setSize(1150, 550);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//EXIT_ON_CLOSE(在JFrame中定义:使用System exit方法退出应用程序,仅在应用程序中使用)
this.setTitle("五子棋客户端");
this.add(qipan,BorderLayout.CENTER);
this.add(talk,BorderLayout.WEST);
this.setVisible(true);
}
}
2、游戏规则按钮功能的添加
public class ClientChessBoard extends JPanel {
Image board, black, white;
int getx = 0, gety = 0;// 获取客户端棋盘坐标
static boolean xiaqi = true;
int cou = 0;//连珠数
String message = ""; // 发送的消息
Send_message sendmessage; // 发送的方法
int hgex = 0, hgey = 0;
public static String control; // 按钮控制
public static boolean isgamestart = false;
public static boolean myselfok = false; // 为true表示自己准备好了
public static boolean duifangok = false; // 为true表示对方准备好了
public static boolean ismyselfxiaqi = true; // 轮到自己下了
public static boolean isduifangxiaqi = false; // 轮到对方下了
private MouseEvent xiaqie; // 下白棋的时候,白棋点的鼠标位置的全局变量
public static ArrayList<String> myself_list = new ArrayList<String>();// 自己下棋的数集
public static ArrayList<String> duifang_list = new ArrayList<String>(); // 对方下棋的数集
public ClientChessBoard() {
sendmessage = new Send_message(message, ClientChat.socket);// 创建一个对象,并且实例化
this.setLayout(null);
JButton ks = new J