预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共48页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

第8章JavaSocket网络编程案例23456789101112131415161718192021228.3ClientUserControlPaduserControlPad=newUserControlPad();//用户操作区 UserInputPaduserInputPad=newUserInputPad();//用户输入区 FIRPadfirPad=newFIRPad();//下棋区 PanelsouthPanel=newPanel();//面板区 PanelnorthPanel=newPanel(); PanelcenterPanel=newPanel(); PaneleastPanel=newPanel(); publicFIRClient() { super("Java五子棋客户端"); setLayout(newBorderLayout()); host=userControlPad.ipInputted.getText(); eastPanel.setLayout(newBorderLayout()); eastPanel.add(userListPad,BorderLayout.NORTH); eastPanel.add(userChatPad,BorderLayout.CENTER); eastPanel.setBackground(Color.LIGHT_GRAY); userInputPad.contentInputted.addKeyListener(this); firPad.host=userControlPad.ipInputted.getText(); centerPanel.add(firPad,BorderLayout.CENTER); centerPanel.add(userInputPad,BorderLayout.SOUTH); centerPanel.setBackground(Color.LIGHT_GRAY); userControlPad.connectButton.addActionListener(this); userControlPad.createButton.addActionListener(this); userControlPad.joinButton.addActionListener(this); userControlPad.cancelButton.addActionListener(this); userControlPad.exitButton.addActionListener(this); userControlPad.createButton.setEnabled(false); userControlPad.joinButton.setEnabled(false); userControlPad.cancelButton.setEnabled(false); southPanel.add(userControlPad,BorderLayout.CENTER); southPanel.setBackground(Color.LIGHT_GRAY); addWindowListener(newWindowAdapter() { publicvoidwindowClosing(WindowEvente) { if(isOnChat){//聊天中 try{//关闭客户端套接口 clientSocket.close(); }catch(Exceptioned){} } if(isOnChess||isGameConnected){//下棋中 try{//关闭下棋端口 firPad.chessSocket.close(); } catch(Exceptionee){} } System.exit(0); } });add(eastPanel,BorderLayout.EAST); add(centerPanel,BorderLayout.CENTER); add(southPanel,BorderLayout.SOUTH); pack(); setSize(670,560); setVisible(true); setResizable(false); this.validate(); } publicbooleanconnectToServer(StringserverIP,intserverPort)throwsException{ try{ clientSocket=newSocket(serverIP,serverPort); inputStream=new DataInputStream(clientSocket.getInp