欢迎来到天天文库
浏览记录
ID:39892632
大小:209.50 KB
页数:37页
时间:2019-07-14
《java网络五子棋》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、java网络五子棋下面的源代码分为4个文件;chessClient.java:客户端主程序。chessInterface.java:客户端的界面。chessPad.java:棋盘的绘制。chessServer.java:服务器端。可同时容纳50个人同时在线下棋,聊天。没有加上详细注释,不过绝对可以运行,j2sdk1.4下通过。/***************************************************************************************
2、******1.chessClient.java**********************************************************************************************/importjava.awt.*;importjava.awt.event.*;importjava.io.*;importjava.net.*;importjava.util.*;classclientThreadextendsThread{chessClient
3、chessclient;clientThread(chessClientchessclient){this.chessclient=chessclient;}publicvoidacceptMessage(StringrecMessage){if(recMessage.startsWith("/userlist")){StringTokenizeruserToken=newStringTokenizer(recMessage,"");intuserNumber=0;chessclient.userp
4、ad.userList.removeAll();chessclient.inputpad.userChoice.removeAll();chessclient.inputpad.userChoice.addItem("所有人");while(userToken.hasMoreTokens()){Stringuser=(String)userToken.nextToken("");if(userNumber>0&&!user.startsWith("[inchess]")){chessclient.u
5、serpad.userList.add(user);chessclient.inputpad.userChoice.addItem(user);}userNumber++;}chessclient.inputpad.userChoice.select("所有人");}elseif(recMessage.startsWith("/yourname")){chessclient.chessClientName=recMessage.substring(10);chessclient.setTitle("
6、Java五子棋客户端"+"用户名:"+chessclient.chessClientName);}elseif(recMessage.equals("/reject")){try{chessclient.chesspad.statusText.setText("不能加入游戏");chessclient.controlpad.cancelGameButton.setEnabled(false);chessclient.controlpad.joinGameButton.setEnabled(true)
7、;chessclient.controlpad.creatGameButton.setEnabled(true);}catch(Exceptionef){chessclient.chatpad.chatLineArea.setText("chessclient.chesspad.chessSocket.close无法关闭");}chessclient.controlpad.joinGameButton.setEnabled(true);}elseif(recMessage.startsWith("/
8、peer")){chessclient.chesspad.chessPeerName=recMessage.substring(6);if(chessclient.isServer){chessclient.chesspad.chessColor=1;chessclient.chesspad.isMouseEnabled=true;chessclient.chesspad.statusText.setText("请黑棋下子");}elseif(chessclient.
此文档下载收益归作者所有