• 大小: 2.68MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-11
  • 语言: Java
  • 标签: java  socket  

资源简介

利用JAVA开发的socket五子棋编程,实现网络版对战的五子棋,可聊天,可认输,最新下的棋子有红点标记,可人机对战,有图形化界面,有背景图片。

资源截图

代码片段和文件信息

package socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author dmt
 */
public class Client implements Runnable{
    int xPosyPosrexPosreyPos;
    String str;
    String text=null;
    Socket client;
    
    BufferedReader br;
    PrintWriter pw;
    public Client(){
        try{
            String IP = (String) JOptionPane.showInputDialog(null “请输入对方的IP地址:\n“ “请输入IP地址“ JOptionPane.PLAIN_MESSAGE null null
                “127.0.0.1“);
            String port= (String) JOptionPane.showInputDialog(null “请输入对方的端口号:\n“ “请输入端口号“ JOptionPane.PLAIN_MESSAGE null null
                “50000“);
            if(port!=null){
            int port1=Integer.parseInt(port);
           client = new Socket(IPport1);
           new Thread(this).start();
           send_pw s=new send_pw();
           new Thread(s).start();
            }else System.exit(0);
        }catch(Exception e){e.printStackTrace();}
    }
    public void run(){
        try {
            int result;
            br = new BufferedReader(
                    new InputStreamReader(
                            client.getInputStream()));
           while(true){
               
               str=br.readLine();
               if(str!=null){
                result=str.indexOf(“|“);
                if(result!=-1){
                rexPos=Integer.parseInt(str.substring(0result));
                reyPos=Integer.parseInt(str.substring(result+1));
                }
                else
                    text=str;
            System.out.println(result);
               }else text=null;
           }
        } catch (IOException ex) {
            Logger.getLogger(Client.class.getName()).log(Level.SEVERE null ex);
        }
    }
    public class send_pw implements Runnable{
        public void run(){
            try {
                pw = new PrintWriter(
                        new OutputStreamWriter(
                                client.getOutputStream()));
            } catch (IOException ex) {
                Logger.getLogger(Client.class.getName()).log(Level.SEVERE null ex);
            }
        }
    }
    public void transmmit(String s){
        pw.println(s);
        pw.flush();
    }
    public void close(){
        try {
            pw.close();
            br.close();
            client.close();
        } catch (IOException ex) {
            Logger.getLogger(Client.class.getName()).log(Level.SEVERE null ex);
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-12-10 21:18  socket\
     目录           0  2018-12-10 21:18  socket\build\
     文件          52  2018-12-10 21:18  socket\build\built-jar.properties
     目录           0  2018-12-10 22:27  socket\build\classes\
     文件           0  2018-12-10 22:27  socket\build\classes\.netbeans_automatic_build
     文件           0  2018-12-10 22:27  socket\build\classes\.netbeans_update_resources
     目录           0  2018-12-11 00:15  socket\build\classes\socket\
     文件        1283  2018-12-10 22:27  socket\build\classes\socket\Client$send_pw.class
     文件        3130  2018-12-10 22:27  socket\build\classes\socket\Client.class
     文件         762  2018-12-10 22:27  socket\build\classes\socket\Computer.class
     文件        2115  2018-12-11 00:15  socket\build\classes\socket\Gobang_Client$1.class
     文件         984  2018-12-11 00:15  socket\build\classes\socket\Gobang_Client$2.class
     文件        1083  2018-12-11 00:15  socket\build\classes\socket\Gobang_Client$3.class
     文件        1056  2018-12-11 00:15  socket\build\classes\socket\Gobang_Client$4.class
     文件        1266  2018-12-11 00:15  socket\build\classes\socket\Gobang_Client$5.class
     文件        1507  2018-12-11 00:15  socket\build\classes\socket\Gobang_Client$6.class
     文件         201  2018-12-11 00:15  socket\build\classes\socket\Gobang_Client$7.class
     文件        1717  2018-12-11 00:15  socket\build\classes\socket\Gobang_Client$GameMap.class
     文件        7963  2018-12-11 00:15  socket\build\classes\socket\Gobang_Client.class
     文件        2132  2018-12-11 00:15  socket\build\classes\socket\Gobang_Server$1.class
     文件         984  2018-12-11 00:15  socket\build\classes\socket\Gobang_Server$2.class
     文件        1083  2018-12-11 00:15  socket\build\classes\socket\Gobang_Server$3.class
     文件        1056  2018-12-11 00:15  socket\build\classes\socket\Gobang_Server$4.class
     文件        1268  2018-12-11 00:15  socket\build\classes\socket\Gobang_Server$5.class
     文件        1507  2018-12-11 00:15  socket\build\classes\socket\Gobang_Server$6.class
     文件         201  2018-12-11 00:15  socket\build\classes\socket\Gobang_Server$7.class
     文件         201  2018-12-10 23:51  socket\build\classes\socket\Gobang_Server$8.class
     文件        1717  2018-12-11 00:15  socket\build\classes\socket\Gobang_Server$GameMap.class
     文件        7978  2018-12-11 00:15  socket\build\classes\socket\Gobang_Server.class
     文件         740  2018-12-11 00:15  socket\build\classes\socket\NewJframe$1.class
     文件         740  2018-12-11 00:15  socket\build\classes\socket\NewJframe$2.class
............此处省略37个文件信息

评论

共有 条评论