用Java编了一个双人聊天的软件。 又做了一个简易聊天界面。怎么能让组合起来聊天。 20
界面和聊天部分,分开可以运行,聊天部分在cmd命令里边可以聊天,怎么可以再聊天界面中显示,不用CMD。求大神详细说下。QQ382594333聊天部分的代码:importj...
界面和聊天部分,分开可以运行,聊天部分在cmd命令里边可以聊天,怎么可以再聊天界面中显示,不用CMD。求大神详细说下。QQ382594333
聊天部分的代码:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class TalkClient {
public static void main(String[] args) {
try {
Socket socket=new Socket("192.168.1.109",4700);
BufferedReader sin=new BufferedReader(new InputStreamReader(System.in));
PrintWriter os=new PrintWriter(socket.getOutputStream());
BufferedReader is=new BufferedReader(new InputStreamReader(socket.getInputStream()));
String readline;
readline=sin.readLine();
while(!readline.equals("bye")){
os.println(readline);
os.flush();
System.out.println("Client:"+readline);
System.out.println("Server:"+is.readLine());
readline=sin.readLine();
}
os.close();
is.close();
socket.close();
} catch (IOException e) {
System.out.println("Error:"+e);
}
}
} 展开
聊天部分的代码:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class TalkClient {
public static void main(String[] args) {
try {
Socket socket=new Socket("192.168.1.109",4700);
BufferedReader sin=new BufferedReader(new InputStreamReader(System.in));
PrintWriter os=new PrintWriter(socket.getOutputStream());
BufferedReader is=new BufferedReader(new InputStreamReader(socket.getInputStream()));
String readline;
readline=sin.readLine();
while(!readline.equals("bye")){
os.println(readline);
os.flush();
System.out.println("Client:"+readline);
System.out.println("Server:"+is.readLine());
readline=sin.readLine();
}
os.close();
is.close();
socket.close();
} catch (IOException e) {
System.out.println("Error:"+e);
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询