国产偷录视频叫床高潮,国产精品久久久久久影视,国产乱理伦片a级在线观看,国产精品无码a∨精品影院,国产片av国语在线观看

五子棋網(wǎng)絡(luò)游戲

下面的源代碼分為4個(gè)文件;

chessClient.java:客戶端主程序。

chessInterface.java:客戶端的界面。

chessPad.java:棋盤的繪制。

chessServer.java:服務(wù)器端。

可同時(shí)容納50個(gè)人同時(shí)在線下棋,聊天。

沒有加上詳細(xì)注釋,不過絕對(duì)可以運(yùn)行,j2sdk1.4下通過。

/*********************************************************************************************

1.chessClient.java

**********************************************************************************************/

importjava.awt.*;

importjava.awt.event.*;

importjava.io.*;

importjava.net.*;

importjava.util.*;

classclientThreadextendsThread

{

chessClientchessclient;

clientThread(chessClientchessclient)

{

this.chessclient=chessclient;

}

publicvoidacceptMessage(StringrecMessage)

{

if(recMessage.startsWith(/userlist))

{

StringTokenizeruserToken=newStringTokenizer(recMessage,);

intuserNumber=0;

chessclient.userpad.userList.removeAll();

chessclient.inputpad.userChoice.removeAll();

chessclient.inputpad.userChoice.addItem(所有人);

while(userToken.hasMoreTokens())

{

Stringuser=(String)userToken.nextToken();

if(userNumber>0&&!user.startsWith([inchess]))

{

chessclient.userpad.userList.add(user);

chessclient.inputpad.userChoice.addItem(user);

}

userNumber++;

}

chessclient.inputpad.userChoice.select(所有人);

}

elseif(recMessage.startsWith(/yourname))

{

chessclient.chessClientName=recMessage.substring(10);

chessclient.setTitle(Java五子棋客戶端+用戶名:+chessclient.chessClientName);

}

elseif(recMessage.equals(/reject))

{

try

{

chessclient.chesspad.statusText.setText(不能加入游戲);

chessclient.controlpad.cancelGameButton.setEnabled(false);

chessclient.controlpad.joinGameButton.setEnabled(true);

chessclient.controlpad.creatGameButton.setEnabled(true);

}

catch(Exceptionef)

{

chessclient.chatpad.chatLineArea.setText(chessclient.chesspad.chessSocket.close無法關(guān)閉);

}

chessclient.controlpad.joinGameButton.setEnabled(true);

}

elseif(recMessage.startsWith(/peer))

{

chessclient.chesspad.chessPeerName=recMessage.substring(6);

if(chessclient.isServer)

{

chessclient.chesspad.chessColor=1;

chessclient.chesspad.isMouseEnabled=true;

chessclient.chesspad.statusText.setText(請(qǐng)黑棋下子);

}

elseif(chessclient.isClient)

{

chessclient.chesspad.chessColor=-1;

chessclient.chesspad.statusText.setText(已加入游戲,等待對(duì)方下子...);

}

}

elseif(recMessage.equals(/youwin))

{

chessclient.isOnChess=false;

chessclient.chesspad.chessVictory(chessclient.chesspad.chessColor);

chessclient.chesspad.statusText.setText(對(duì)方退出,請(qǐng)點(diǎn)放棄游戲退出連接);

chessclient.chesspad.isMouseEnabled=false;

}

elseif(recMessage.equals(/OK))

{

chessclient.chesspad.statusText.setText(創(chuàng)建游戲成功,等待別人加入...);

}

elseif(recMessage.equals(/error))

{

chessclient.chatpad.chatLineArea.append(傳輸錯(cuò)誤:請(qǐng)退出程序,重新加入\n);

}

else

{

chessclient.chatpad.chatLineArea.append(recMessage+\n);

chessclient.chatpad.chatLineArea.setCaretPosition(

chessclient.chatpad.chatLineArea.getText().length());

}

}

publicvoidrun()

{

Stringmessage=;

try

{

while(true)

{

message=chessclient.in.readUTF();

acceptMessage(message);

}

}

catch(IOExceptiones)

{

}

}

}

publicclasschessClientextendsFrameimplementsActionListener,KeyListener

{

userPaduserpad=newuserPad();

chatPadchatpad=newchatPad();

controlPadcontrolpad=newcontrolPad();

chessPadchesspad=newchessPad();

inputPadinputpad=newinputPad();

SocketchatSocket;

DataInputStreamin;

DataOutputStreamout;

StringchessClientName=null;

Stringhost=null;

intport=4331;

booleanisOnChat=false;//在聊天?

booleanisOnChess=false;//在下棋?

booleanisGameConnected=false;//下棋的客戶端連接?

booleanisServer=false;//如果是下棋的主機(jī)

booleanisClient=false;//如果是下棋的客戶端

PanelsouthPanel=newPanel();

PanelnorthPanel=newPanel();

PanelcenterPanel=newPanel();

PanelwestPanel=newPanel();

PaneleastPanel=newPanel();

chessClient()

{

super(Java五子棋客戶端);

setLayout(newBorderLayout());

host=controlpad.inputIP.getText();

westPanel.setLayout(newBorderLayout());

westPanel.add(userpad,BorderLayout.NORTH);

westPanel.add(chatpad,BorderLayout.CENTER);

westPanel.setBackground(Color.pink);

inputpad.inputWords.addKeyListener(this);

chesspad.host=controlpad.inputIP.getText();

centerPanel.add(chesspad,BorderLayout.CENTER);

centerPanel.add(inputpad,BorderLayout.SOUTH);

centerPanel.setBackground(Color.pink);

controlpad.connectButton.addActionListener(this);

controlpad.creatGameButton.addActionListener(this);

controlpad.joinGameButton.addActionListener(this);

controlpad.cancelGameButton.addActionListener(this);

controlpad.exitGameButton.addActionListener(this);

controlpad.creatGameButton.setEnabled(false);

controlpad.joinGameButton.setEnabled(false);

controlpad.cancelGameButton.setEnabled(false);

southPanel.add(controlpad,BorderLayout.CENTER);

southPanel.setBackground(Color.pink);

addWindowListener(newWindowAdapter()

{

publicvoidwindowClosing(WindowEvente)

{

if(isOnChat)

{

try

{

chatSocket.close();

}

catch(Exceptioned)

{

}

}

if(isOnChess||isGameConnected)

{

try

{

chesspad.chessSocket.close();

}

catch(Exceptionee)

{

}

}

System.exit(0);

}

publicvoidwindowActivated(WindowEventea)

{

}

});

add(westPanel,BorderLayout.WEST);

add(centerPanel,BorderLayout.CENTER);

add(southPanel,BorderLayout.SOUTH);

pack();

setSize(670,548);

setVisible(true);

setResizable(false);

validate();

}

publicbooleanconnectServer(StringserverIP,intserverPort)throwsException

{

try

{

chatSocket=newSocket(serverIP,serverPort);

in=newDataInputStream(chatSocket.getInputStream());

out=newDataOutputStream(chatSocket.getOutputStream());

clientThreadclientthread=newclientThread(this);

clientthread.start();

isOnChat=true;

returntrue;

}

catch(IOExceptionex)

{

chatpad.chatLineArea.setText(chessClient:connectServer:無法連接,建議重新啟動(dòng)程序\n);

}

returnfalse;

}

publicvoidactionPerformed(ActionEvente)

{

if(e.getSource()==controlpad.connectButton)

{

host=chesspad.host=controlpad.inputIP.getText();

try

{

if(connectServer(host,port))

{

chatpad.chatLineArea.setText();

controlpad.connectButton.setEnabled(false);

controlpad.creatGameButton.setEnabled(true);

controlpad.joinGameButton.setEnabled(true);

chesspad.statusText.setText(連接成功,請(qǐng)創(chuàng)建游戲或加入游戲);

}

}

catch(Exceptionei)

{

chatpad.chatLineArea.setText(controlpad.connectButton:無法連接,建議重新啟動(dòng)程序\n);

}

}

if(e.getSource()==controlpad.exitGameButton)

{

if(isOnChat)

{

try

{

chatSocket.close();

}

catch(Exceptioned)

{

}

}

if(isOnChess||isGameConnected)

{

try

{

chesspad.chessSocket.close();

}

catch(Exceptionee)

{

}

}

System.exit(0);

}

if(e.getSource()==controlpad.joinGameButton)

{

StringselectedUser=userpad.userList.getSelectedItem();

if(selectedUser==null||selectedUser.startsWith([inchess])||

selectedUser.equals(chessClientName))

{

chesspad.statusText.setText(必須先選定一個(gè)有效用戶);

}

else

{

try

{

if(!isGameConnected)

{

if(chesspad.connectServer(chesspad.host,chesspad.port))

{

isGameConnected=true;

isOnChess=true;

isClient=true;

controlpad.creatGameButton.setEnabled(false);

controlpad.joinGameButton.setEnabled(false);

controlpad.cancelGameButton.setEnabled(true);

chesspad.chessthread.sendMessage(/joingame+userpad.userList.getSelectedItem()++chessClientName);

}

}

else

{

isOnChess=true;

isClient=true;

controlpad.creatGameButton.setEnabled(false);

controlpad.joinGameButton.setEnabled(false);

controlpad.cancelGameButton.setEnabled(true);

chesspad.chessthread.sendMessage(/joingame+userpad.userList.getSelectedItem()++chessClientName);

}

}

catch(Exceptionee)

{

isGameConnected=false;

isOnChess=false;

isClient=false;

controlpad.creatGameButton.setEnabled(true);

controlpad.joinGameButton.setEnabled(true);

controlpad.cancelGameButton.setEnabled(false);

chatpad.chatLineArea.setText(chesspad.connectServer無法連接\n+ee);

}

}

}

if(e.getSource()==controlpad.creatGameButton)

{

try

{

if(!isGameConnected)

{

if(chesspad.connectServer(chesspad.host,chesspad.port))

{

isGameConnected=true;

isOnChess=true;

isServer=true;

controlpad.creatGameButton.setEnabled(false);

controlpad.joinGameButton.setEnabled(false);

controlpad.cancelGameButton.setEnabled(true);

chesspad.chessthread.sendMessage(/creatgame+[inchess]+chessClientName);

}

}

else

{

isOnChess=true;

isServer=true;

controlpad.creatGameButton.setEnabled(false);

controlpad.joinGameButton.setEnabled(false);

controlpad.cancelGameButton.setEnabled(true);

chesspad.chessthread.sendMessage(/creatgame+[inchess]+chessClientName);

}

}

catch(Exceptionec)

{

isGameConnected=false;

isOnChess=false;

isServer=false;

controlpad.creatGameButton.setEnabled(true);

controlpad.joinGameButton.setEnabled(true);

controlpad.cancelGameButton.setEnabled(false);

ec.printStackTrace();

chatpad.chatLineArea.setText(chesspad.connectServer無法連接\n+ec);

}

}

if(e.getSource()==controlpad.cancelGameButton)

{

if(isOnChess)

{

chesspad.chessthread.sendMessage(/giveup+chessClientName);

chesspad.chessVictory(-1*chesspad.chessColor);

controlpad.creatGameButton.setEnabled(true);

controlpad.joinGameButton.setEnabled(true);

controlpad.cancelGameButton.setEnabled(false);

chesspad.statusText.setText(請(qǐng)建立游戲或者加入游戲);

}

if(!isOnChess)

{

controlpad.creatGameButton.setEnabled(true);

controlpad.joinGameButton.setEnabled(true);

controlpad.cancelGameButton.setEnabled(false);

chesspad.statusText.setText(請(qǐng)建立游戲或者加入游戲);

}

isClient=isServer=false;

}

}

publicvoidkeyPressed(KeyEvente)

{

TextFieldinputWords=(TextField)e.getSource();

if(e.getKeyCode()==KeyEvent.VK_ENTER)

{

if(inputpad.userChoice.getSelectedItem().equals(所有人))

{

try

{

out.writeUTF(inputWords.getText());

inputWords.setText();

}

catch(Exceptionea)

{

chatpad.chatLineArea.setText(chessClient:KeyPressed無法連接,建議重新連接\n);

userpad.userList.removeAll();

inputpad.userChoice.removeAll();

inputWords.setText();

controlpad.connectButton.setEnabled(true);

}

}

else

{

try

{

out.writeUTF(/+inputpad.userChoice.getSelectedItem()++inputWords.getText());

inputWords.setText();

}

catch(Exceptionea)

{

chatpad.chatLineArea.setText(chessClient:KeyPressed無法連接,建議重新連接\n);

userpad.userList.removeAll();

inputpad.userChoice.removeAll();

inputWords.setText();

controlpad.connectButton.setEnabled(true);

}

}

}

}

publicvoidkeyTyped(KeyEvente)

{

}

publicvoidkeyReleased(KeyEvente)

{

}

publicstaticvoidmain(Stringargs[])

{

chessClientchessClient=newchessClient();

}

}

/******************************************************************************************

下面是:chessInteface.java

******************************************************************************************/

importjava.awt.*;

importjava.awt.event.*;

importjava.io.*;

importjava.net.*;

classuserPadextendsPanel

{

ListuserList=newList(10);

userPad()

{

setLayout(newBorderLayout());

for(inti=0;i<50;i++)

{

userList.add(i+.+沒有用戶);

}

add(userList,BorderLayout.CENTER);

}

}

classchatPadextendsPanel

{

TextAreachatLineArea=newTextArea(,18,30,TextArea.SCROLLBARS_VERTICAL_ONLY);

chatPad()

{

setLayout(newBorderLayout());

add(chatLineArea,BorderLayout.CENTER);

}

}

classcontrolPadextendsPanel

{

LabelIPlabel=newLabel(IP,Label.LEFT);

TextFieldinputIP=newTextField(localhost,10);

ButtonconnectButton=newButton(連接主機(jī));

ButtoncreatGameButton=newButton(建立游戲);

ButtonjoinGameButton=newButton(加入游戲);

ButtoncancelGameButton=newButton(放棄游戲);

ButtonexitGameButton=newButton(關(guān)閉程序);

controlPad()

{

setLayout(newFlowLayout(FlowLayout.LEFT));

setBackground(Color.pink);

add(IPlabel);

add(inputIP);

add(connectButton);

add(creatGameButton);

add(joinGameButton);

add(cancelGameButton);

add(exitGameButton);

}

}

classinputPadextendsPanel

{

TextFieldinputWords=newTextField(,40);

ChoiceuserChoice=newChoice();

inputPad()

{

setLayout(newFlowLayout(FlowLayout.LEFT));

for(inti=0;i<50;i++)

{

userChoice.addItem(i+.+沒有用戶);

}

userChoice.setSize(60,24);

add(userChoice);

add(inputWords);

}

}

/**********************************************************************************************

下面是:chessPad.java

**********************************************************************************************/

importjava.awt.*;

importjava.awt.event.*;

importjava.io.*;

importjava.net.*;

importjava.util.*;

classchessThreadextendsThread

{

chessPadchesspad;

chessThread(chessPadchesspad)

{

this.chesspad=chesspad;

}

publicvoidsendMessage(StringsndMessage)

{

try

{

chesspad.outData.writeUTF(sndMessage);

}

catch(Exceptionea)

{

System.out.println(chessThread.sendMessage:+ea);

}

}

publicvoidacceptMessage(StringrecMessage)

{

if(recMessage.startsWith(/chess))

{

StringTokenizeruserToken=newStringTokenizer(recMessage,);

StringchessToken;

String[]chessOpt={-1,-1,0};

intchessOptNum=0;

while(userToken.hasMoreTokens())

{

chessToken=(String)userToken.nextToken();

if(chessOptNum>=1&&chessOptNum<=3)

{

chessOpt[chessOptNum-1]=chessToken;

}

chessOptNum++;

}

chesspad.netChessPaint(Integer.parseInt(chessOpt[0]),Integer.parseInt(chessOpt[1]),Integer.parseInt(chessOpt[2]));

}

elseif(recMessage.startsWith(/yourname))

{

chesspad.chessSelfName=recMessage.substring(10);

}

elseif(recMessage.equals(/error))

{

chesspad.statusText.setText(錯(cuò)誤:沒有這個(gè)用戶,請(qǐng)退出程序,重新加入);

}

else

{

//System.out.println(recMessage);

}

}

publicvoidrun()

{

Stringmessage=;

try

{

while(true)

{

message=chesspad.inData.readUTF();

acceptMessage(message);

}

}

catch(IOExceptiones)

{

}

}

}

classchessPadextendsPanelimplementsMouseListener,ActionListener

{

intchessPoint_x=-1,chessPoint_y=-1,chessColor=1;

intchessBlack_x[]=newint[200];

intchessBlack_y[]=newint[200];

intchessWhite_x[]=newint[200];

intchessWhite_y[]=newint[200];

intchessBlackCount=0,chessWhiteCount=0;

intchessBlackWin=0,chessWhiteWin=0;

booleanisMouseEnabled=false,isWin=false,isInGame=false;

TextFieldstatusText=newTextField(請(qǐng)先連接服務(wù)器);

SocketchessSocket;

DataInputStreaminData;

DataOutputStreamoutData;

StringchessSelfName=null;

StringchessPeerName=null;

Stringhost=null;

intport=4331;

chessThreadchessthread=newchessThread(this);

chessPad()

{

setSize(440,440);

setLayout(null);

setBackground(Color.pink);

addMouseListener(this);

add(statusText);

statusText.setBounds(40,5,360,24);

statusText.setEditable(false);

}

publicbooleanconnectServer(StringServerIP,intServerPort)throwsException

{

try

{

chessSocket=newSocket(ServerIP,ServerPort);

inData=newDataInputStream(chessSocket.getInputStream());

outData=newDataOutputStream(chessSocket.getOutputStream());

chessthread.start();

returntrue;

}

catch(IOExceptionex)

{

statusText.setText(chessPad:connectServer:無法連接\n);

}

returnfalse;

}

publicvoidchessVictory(intchessColorWin)

{

this.removeAll();

for(inti=0;i<=chessBlackCount;i++)

{

chessBlack_x[i]=0;

chessBlack_y[i]=0;

}

for(inti=0;i<=chessWhiteCount;i++)

{

chessWhite_x[i]=0;

chessWhite_y[i]=0;

}

chessBlackCount=0;

chessWhiteCount=0;

add(statusText);

statusText.setBounds(40,5,360,24);

if(chessColorWin==1)

{chessBlackWin++;

statusText.setText(黑棋勝,黑:白為+chessBlackWin+:+chessWhiteWin+,重新開局,等待白棋下子...);

}

elseif(chessColorWin==-1)

{

chessWhiteWin++;

statusText.setText(白棋勝,黑:白為+chessBlackWin+:+chessWhiteWin+,重新開局,等待黑棋下子...);

}

}

publicvoidgetLocation(inta,intb,intcolor)

{

if(color==1)

{

chessBlack_x[chessBlackCount]=a*20;

chessBlack_y[chessBlackCount]=b*20;

chessBlackCount++;

}

elseif(color==-1)

{

chessWhite_x[chessWhiteCount]=a*20;

chessWhite_y[chessWhiteCount]=b*20;

chessWhiteCount++;

}

}

publicbooleancheckWin(inta,intb,intcheckColor)

{

intstep=1,chessLink=1,chessLinkTest=1,chessCompare=0;

if(checkColor==1)

{

chessLink=1;

for(step=1;step<=4;step++)

{

for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)

{

if(((a+step)*20==chessBlack_x[chessCompare])&&((b*20)==chessBlack_y[chessCompare]))

{

chessLink=chessLink+1;

if(chessLink==5)

{

return(true);

}

}

}

if(chessLink==(chessLinkTest+1))

chessLinkTest++;

else

break;

}

for(step=1;step<=4;step++)

{

for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)

{

if(((a-step)*20==chessBlack_x[chessCompare])&&(b*20==chessBlack_y[chessCompare]))

{

chessLink++;

if(chessLink==5)

{

return(true);

}

}

}

if(chessLink==(chessLinkTest+1))

chessLinkTest++;

else

break;

}

chessLink=1;

chessLinkTest=1;

for(step=1;step<=4;step++)

{

for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)

{

if((a*20==chessBlack_x[chessCompare])&&((b+step)*20==chessBlack_y[chessCompare]))

{

chessLink++;

if(chessLink==5)

{

return(true);

}

}

}

if(chessLink==(chessLinkTest+1))

chessLinkTest++;

else

break;

免責(zé)聲明:本站發(fā)布的游戲攻略(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng)。
如果本文侵犯了您的權(quán)益,請(qǐng)聯(lián)系站長(zhǎng)郵箱進(jìn)行舉報(bào)反饋,一經(jīng)查實(shí),我們將在第一時(shí)間處理,感謝您對(duì)本站的關(guān)注!