這種東西,除非是網(wǎng)絡(luò)上原本就有的。否則你幾乎要不到的,即使是簡易版想做出來,除非是高手,起碼要一個星期。
10年積累的成都網(wǎng)站設(shè)計、成都做網(wǎng)站經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認識你,你也不認識我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有柳南免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
1、swing的界面可以直接用netbeans畫出來嘛。
2、可以把輸出的聊天內(nèi)容都放在一個StringBuffer里,每打出一句話,就把這句話追加在StringBuffer,然后把StringBuffer里的內(nèi)容輸出到Textarea中。
3、好友列表可以用JList
【ClientSocketDemo.java 客戶端Java源代碼】
import java.net.*;
import java.io.*;
public class ClientSocketDemo
{
//聲明客戶端Socket對象socket
Socket socket = null;
//聲明客戶器端數(shù)據(jù)輸入輸出流
DataInputStream in;
DataOutputStream out;
//聲明字符串數(shù)組對象response,用于存儲從服務(wù)器接收到的信息
String response[];
//執(zhí)行過程中,沒有參數(shù)時的構(gòu)造方法,本地服務(wù)器在本地,取默認端口10745
public ClientSocketDemo()
{
try
{
//創(chuàng)建客戶端socket,服務(wù)器地址取本地,端口號為10745
socket = new Socket("localhost",10745);
//創(chuàng)建客戶端數(shù)據(jù)輸入輸出流,用于對服務(wù)器端發(fā)送或接收數(shù)據(jù)
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());
//獲取客戶端地址及端口號
String ip = String.valueOf(socket.getLocalAddress());
String port = String.valueOf(socket.getLocalPort());
//向服務(wù)器發(fā)送數(shù)據(jù)
out.writeUTF("Hello Server.This connection is from client.");
out.writeUTF(ip);
out.writeUTF(port);
//從服務(wù)器接收數(shù)據(jù)
response = new String[3];
for (int i = 0; i response.length; i++)
{
response[i] = in.readUTF();
System.out.println(response[i]);
}
}
catch(UnknownHostException e){e.printStackTrace();}
catch(IOException e){e.printStackTrace();}
}
//執(zhí)行過程中,有一個參數(shù)時的構(gòu)造方法,參數(shù)指定服務(wù)器地址,取默認端口10745
public ClientSocketDemo(String hostname)
{
try
{
//創(chuàng)建客戶端socket,hostname參數(shù)指定服務(wù)器地址,端口號為10745
socket = new Socket(hostname,10745);
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());
String ip = String.valueOf(socket.getLocalAddress());
String port = String.valueOf(socket.getLocalPort());
out.writeUTF("Hello Server.This connection is from client.");
out.writeUTF(ip);
out.writeUTF(port);
response = new String[3];
for (int i = 0; i response.length; i++)
{
response[i] = in.readUTF();
System.out.println(response[i]);
}
}
catch(UnknownHostException e){e.printStackTrace();}
catch(IOException e){e.printStackTrace();}
}
//執(zhí)行過程中,有兩個個參數(shù)時的構(gòu)造方法,第一個參數(shù)hostname指定服務(wù)器地址
//第一個參數(shù)serverPort指定服務(wù)器端口號
public ClientSocketDemo(String hostname,String serverPort)
{
try
{
socket = new Socket(hostname,Integer.parseInt(serverPort));
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());
String ip = String.valueOf(socket.getLocalAddress());
String port = String.valueOf(socket.getLocalPort());
out.writeUTF("Hello Server.This connection is from client.");
out.writeUTF(ip);
out.writeUTF(port);
response = new String[3];
for (int i = 0; i response.length; i++)
{
response[i] = in.readUTF();
System.out.println(response[i]);
}
}
catch(UnknownHostException e){e.printStackTrace();}
catch(IOException e){e.printStackTrace();}
}
public static void main(String[] args)
{
String comd[] = args;
if(comd.length == 0)
{
System.out.println("Use localhost(127.0.0.1) and default port");
ClientSocketDemo demo = new ClientSocketDemo();
}
else if(comd.length == 1)
{
System.out.println("Use default port");
ClientSocketDemo demo = new ClientSocketDemo(args[0]);
}
else if(comd.length == 2)
{
System.out.println("Hostname and port are named by user");
ClientSocketDemo demo = new ClientSocketDemo(args[0],args[1]);
}
else System.out.println("ERROR");
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
【ServerSocketDemo.java 服務(wù)器端Java源代碼】
import java.net.*;
import java.io.*;
public class ServerSocketDemo
{
//聲明ServerSocket類對象
ServerSocket serverSocket;
//聲明并初始化服務(wù)器端監(jiān)聽端口號常量
public static final int PORT = 10745;
//聲明服務(wù)器端數(shù)據(jù)輸入輸出流
DataInputStream in;
DataOutputStream out;
//聲明InetAddress類對象ip,用于獲取服務(wù)器地址及端口號等信息
InetAddress ip = null;
//聲明字符串數(shù)組對象request,用于存儲從客戶端發(fā)送來的信息
String request[];
public ServerSocketDemo()
{
request = new String[3]; //初始化字符串數(shù)組
try
{
//獲取本地服務(wù)器地址信息
ip = InetAddress.getLocalHost();
//以PORT為服務(wù)端口號,創(chuàng)建serverSocket對象以監(jiān)聽該端口上的連接
serverSocket = new ServerSocket(PORT);
//創(chuàng)建Socket類的對象socket,用于保存連接到服務(wù)器的客戶端socket對象
Socket socket = serverSocket.accept();
System.out.println("This is server:"+String.valueOf(ip)+PORT);
//創(chuàng)建服務(wù)器端數(shù)據(jù)輸入輸出流,用于對客戶端接收或發(fā)送數(shù)據(jù)
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());
//接收客戶端發(fā)送來的數(shù)據(jù)信息,并顯示
request[0] = in.readUTF();
request[1] = in.readUTF();
request[2] = in.readUTF();
System.out.println("Received messages form client is:");
System.out.println(request[0]);
System.out.println(request[1]);
System.out.println(request[2]);
//向客戶端發(fā)送數(shù)據(jù)
out.writeUTF("Hello client!");
out.writeUTF("Your ip is:"+request[1]);
out.writeUTF("Your port is:"+request[2]);
}
catch(IOException e){e.printStackTrace();}
}
public static void main(String[] args)
{
ServerSocketDemo demo = new ServerSocketDemo();
}
}
首先,學習java GUI編程,學習監(jiān)聽器。建議看馬士兵的視頻。然后上網(wǎng)上down源代碼,分析類,確定類的屬性和方法。第一遍,就是跟著源碼敲一遍,然后分段看,一段一段的看懂,再實現(xiàn)。慢慢就會了。很有收獲滴! 這是高仿QQ2012登錄界面 源代碼
分享題目:javaqq聊天源代碼,源代碼
標題來源:http://www.rwnh.cn/article34/dsigpse.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、商城網(wǎng)站、軟件開發(fā)、手機網(wǎng)站建設(shè)、網(wǎng)站改版、品牌網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)