package com.jicq;
import java.awt.AWTEvent;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.FlowLayout;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
//以下是主程序
public class MainWin extends JFrame implements Runnable {
JPanel contentPane;
String filepath;
String filename;
String file;
//以下是好友基本信息变量,比如呢称,ip地址等
Vector friendnames = new Vector();
int friendnum;//friend number
private String[] picsonline = new String[] { "1.jpg", "3.jpg", "5.jpg",
"7.jpg" };
private String[] picsoffline = new String[] { "2.jpg", "4.jpg", "6.jpg",
"8.jpg" };
Vector friendjicq = new Vector();
Vector udpport = new Vector();
Vector friendips = new Vector();
Vector friendemail = new Vector();
Vector friendsex = new Vector();
Vector friendinfo = new Vector();
Vector picno = new Vector();
Vector status = new Vector();
//以下是临时变量保存临时的好友
Vector tempname = new Vector();
Vector tempjicq = new Vector();
Vector tempip = new Vector();
Vector temppic = new Vector();
Vector tempstatus = new Vector();
Vector whoaddmesip = new Vector();//get whoaddme as friend
Vector tempemail = new Vector();
Vector tempinfo = new Vector();
int index;//get list index
int index3;//get firiend onlineinfo
int index4;//get message from info
boolean fromunknow = false;
//以下建立窗口类
FindFriend2 findf;
JDialog hello = new JDialog();
JDialog OneAddyou = new JDialog();
JDialog DirectAdd = new JDialog();
int tempgetjicq;//get the tempgetjicq
/////////////////////////////friend info
//以下是程序界面的变量
ImageIcon icon1 = new ImageIcon("cab_small.gif");
ImageIcon icon6 = new ImageIcon("sun_small.gif");
ImageIcon icon3 = new ImageIcon("17.jpg");
JButton jButton1 = new JButton();
JDialog about = new JDialog();
JDialog senddata = new JDialog();
JDialog getdata = new JDialog();
JButton ok = new JButton();
JPopupMenu jPopupMenu1 = new JPopupMenu();
JMenuItem sendmessage = new JMenuItem();
JMenuItem getmessage = new JMenuItem();
JMenuItem sendfile = new JMenuItem();
JMenuItem lookinfo = new JMenuItem();
JMenuItem chatrecord = new JMenuItem();
JLabel name = new JLabel();
JTextField nametext = new JTextField();
JLabel icq = new JLabel();
JTextField icqno = new JTextField();
JButton send = new JButton();
JButton cancel = new JButton();
JTextArea sendtext = new JTextArea();
JList list;
JLabel jLabel2 = new JLabel();
FlowLayout flowLayout1 = new FlowLayout();
JMenuBar mb = new JMenuBar();
JMenu filemenu = new JMenu("好友操作");
JMenuItem exititem = new JMenuItem("Exit");
JMenuItem find = new JMenuItem("查找好友");
JMenuItem direct = new JMenuItem("直接添加好友");
JMenuItem update = new JMenuItem("更新好友列表");
JMenuItem online = new JMenuItem("上线通知");
JMenuItem myinfo = new JMenuItem("陌生人");
//以下是网络相关变量
Socket socket;
BufferedReader in;
PrintWriter out;
DatagramPacket sendPacket, receivePacket;
DatagramSocket sendSocket, receiveSocket;
int udpPORT = 5001;
int sendPort = 5000;
String server;
int serverport;
byte array[] = new byte[512];
Thread thread;
int myjicq;
String received;
//以下是程序界面的变量
JLabel jLabel3 = new JLabel();
JTextField getfromname = new JTextField();
JLabel jLabel4 = new JLabel();
JTextField getfromjicq = new JTextField();
JTextArea getinfo = new JTextArea();
JButton getok = new JButton();
String theip;
JMenuItem delfriend = new JMenuItem();
JLabel jLabel1 = new JLabel();
JTextField helloname = new JTextField();
JLabel jLabel5 = new JLabel();
JTextField hellojicq = new JTextField();
JLabel jLabel6 = new JLabel();
JTextField helloemail = new JTextField();
JLabel jLabel7 = new JLabel();
JTextArea helloinfo = new JTextArea();
JButton jButton3 = new JButton();
JButton hellook = new JButton();
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
JLabel jLabel10 = new JLabel();
JLabel oneaddme = new JLabel();
JButton addit = new JButton();
JButton iknow = new JButton();
JLabel jLabel11 = new JLabel();
JLabel jLabel12 = new JLabel();
JLabel jLabel13 = new JLabel();
JTextField hellosex = new JTextField();
JTextField friendid = new JTextField();
JButton directaddok = new JButton();
/* 以下该函数连接服务器 */
public void ConnectServer(int myid) {
try {
socket = new Socket(InetAddress.getByName(server), serverport);
in = new BufferedReader(new InputStreamReader(socket
.getInputStream()));
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
socket.getOutputStream())), true);
//以下读取好友信息
out.println("friend");
out.println(myid);
friendnum = Integer.parseInt(in.readLine());
String friendname = " ";
String friendjicqno, friendip, friendstatus, picinfo, email, sex, infos;
do {
friendname = in.readLine();
if (friendname.equals("over"))
break;
friendnames.add(friendname);
friendjicqno = in.readLine();
friendjicq.add(new Integer(friendjicqno));
friendip = in.readLine();
friendips.add(friendip);
friendstatus = in.readLine();
status.add(friendstatus);
picinfo = in.readLine();
picno.add(new Integer(picinfo));
email = in.readLine();
friendemail.add(email);
sex = in.readLine();
friendsex.add(sex);
infos = in.readLine();
friendinfo.add(infos);
} while (!friendname.equals("over"));
} catch (IOException e1) {
System.out.println("false");
}
//以下在列表中显示好友
DefaultListModel mm = (DefaultListModel) list.getModel();
int picid;
for (int p = 0; p < friendnames.size(); p++) {
picid = Integer.parseInt(picno.get(p).toString());
if (status.get(p).equals("1")) {
mm.addElement(new Object[] { friendnames.get(p),
new ImageIcon(picsonline[picid]) });
} else {
mm.addElement(new Object[] { friendnames.get(p),
new ImageIcon(picsoffline[picid]) });
}
}//for
}//connectto server
//以下函数无限监听好友的消息
public void run() {
while (true) {
try {
for (int x = 0; x < 512; x++)
array[x] = ' ';
//创建数据报
receivePacket = new DatagramPacket(array, array.length);
receiveSocket.receive(receivePacket);
byte[] data = receivePacket.getData();
String infofromip = receivePacket.getAddress().getHostAddress()
.toString().trim();
index3 = 0;
received = new String(data, 0, data.length);
received.trim();
String tempstr;
int tx;
//
没有合适的资源?快使用搜索试试~ 我知道了~
JAVA网络通信系统设计(源代码)
共80个文件
class:45个
jpg:11个
java:10个
需积分: 0 4 下载量 111 浏览量
2023-01-05
11:53:24
上传
评论
收藏 253KB ZIP 举报
温馨提示
网络通信在当今信息社会中起着不可或缺的作用 ,人们可以利用网络通信技术进行即时的信息交流。例如,人们可以通过Internet搜索所要的信息,通过网上通信工具聊天,交流信息,上网购物等等。 本课题是应用了计算机网络通信技术和JAVA网络编程的基础知识,以JAVA为平台,利用Eclipse开发工具,并使用SQL Server 2000管理数据库数据开发出的基于Socket的网络即时通信系统。系统采用客户机/服务器(C/S)的模式设计,是一个三层C/S结构,数据库服务器、应用程序服务器端、应用程序客户端,按照此设计思想,系统采用C/S结构,可以将任务合理分配到客户机端和服务器端 ,从而降低了系统的通信开销。此系统共分为两个模块:客户端模块和服务器端模块。从操作简便、界面美观、灵活实用的用户要求出发,设计开发的网络通信系统可以实现用户注册,用户登录,消息通信和好友管理等主要功能。
资源推荐
资源详情
资源评论
收起资源包目录
JAVA网络通信系统设计(源代码).zip (80个子文件)
JAVA网络通信系统设计(源代码)
21.bmp 5KB
sun_small.gif.JPG 1KB
4.JPG 1KB
cab_smal.gif 1KB
8.JPG 1KB
13.bmp 5KB
.classpath 429B
Thumbs.db 41KB
src
com
jicq
New.java 5KB
FindFriend2.java 7KB
sunPanel.java 667B
SendFile.java 828B
Register.java 7KB
GetFile.java 1KB
Server.java 17KB
FindListModel.java 2KB
MainWin.java 34KB
NameAndPicListModel.java 3KB
smile.JPG 1KB
1.jpg 1KB
swt-win32-3063.dll 300KB
9.bmp 5KB
15.bmp 5KB
bin
com
jicq
FindFriend2.class 8KB
GetFile.class 2KB
Server.class 1KB
MainWin$14.class 626B
sunPanel.class 1KB
MainWin_sendmessage_mouseAdapter.class 653B
New$1.class 599B
NameAndPicListModel.class 1KB
FindFriend2$4.class 645B
Register.class 7KB
MainWin_list_mouseAdapter.class 632B
MainWin$17.class 645B
HeadpicCellRenderer.class 2KB
MainWin$3.class 626B
MainWin.class 27KB
New.class 6KB
MainWin_cancel_mouseAdapter.class 638B
ServerThread.class 10KB
FindFriend2$2.class 647B
MainWin_ok_mouseAdapter.class 626B
MainWin$9.class 623B
New$3.class 598B
SendFile.class 1KB
FindListCellRenderer.class 2KB
MainWin$5.class 622B
FindFriend2$1.class 647B
Register$1.class 632B
MainWin$10.class 625B
MainWin$16.class 626B
FindFriend2$3.class 646B
NameAndPicListCellRenderer.class 2KB
MainWin$2.class 628B
MainWin$8.class 625B
MainWin$4.class 626B
MainWin$15.class 626B
MainWin$6.class 623B
FindListModel.class 1KB
MainWin$12.class 624B
MainWin$7.class 627B
MainWin$1.class 622B
HeadPicCombobox.class 788B
New$2.class 601B
MainWin$11.class 631B
MainWin_direct_mouseAdapter.class 423B
MainWin$13.class 626B
5.jpg 1KB
cab_small.gif 8KB
hs_err_pid1256.log 4KB
.project 380B
19.bmp 5KB
sun.JPG 29KB
3.jpg 1KB
6.JPG 1KB
7.jpg 1KB
25.bmp 5KB
2.JPG 1KB
11.bmp 5KB
共 80 条
- 1
资源评论
zhangwuji1990
- 粉丝: 1
- 资源: 354
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功