/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clientele;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Vector;
import javax.swing.JOptionPane;
import setting.AudioPlay;
import setting.Embody;
import setting.User;
/**
*
* @author FYX
*/
public class Client {
/**
* 定义全局变量
*/
public String message;
public int id;
public int port1;
public String friendip;
public String friendport;
/**
* 定义Socket 通过"套接字"向网络发出请求或者应答网络请求
*/
private static Socket socket;
/**
客户端主界面
*/
private static ClientMainUI mainUI;
/**
* 树形好友列表
*/
static FriendTree friendTree;
/**
* 修改个人信息基面
*/
static ModifyUserUI modify;
/**
* 登录界面
*/
static LoginUI loginui;
/**
* 注册界面
*/
static UserRegUI userRegUI;
/**
* 发企业信息
*/
private static InchatUI inchatui;
/**
* 消息验证
*/
private static InchatverUI inchatver;
/**
* 消息窗口
*/
private static InchatarrivUI inchatarrivui;
/**
*聊天记录窗口
*/
private static Chatrecord chatrecord;
/**
* 对象输入流
*/
private ObjectInputStream netIn;
/**
* 对象输出流
*/
private ObjectOutputStream netOut;
/**
* 保存用户聊天窗口souceID和destID更据它判断是否需要NEW新的窗口
*/
@SuppressWarnings("unchecked")
private Vector chatUIvector = new Vector();
/**
* 保存用户聊天记录窗口souceID和destID更据它判断是否需要NEW新的窗口
*/
@SuppressWarnings("unchecked")
private Vector chatrecordvector = new Vector();
/**
* 客户端运行标志
*/
private boolean runFlag = true;
/**
* 用来保存自己的信息,其值常改变
*/
private User userInfo;
/**
* 用户登录成功后 信息保存在此对象 其值不再改变 用于获取ID,设置窗体标题
*/
private User constuser = new User();
/**
* 延时接收信令信号量
*/
private static boolean acceptorder = false;
/**
* 控制ClientMainUI中 jLabel显示
*/
private static boolean hidden = true;
/**
* 暂时储存信令
*/
private String ordersave;
/**
* 储存添加好友和下线时的信令
*/
@SuppressWarnings("unchecked")
private Vector orderSys = new Vector();
/**
* 用于客户端其他类调用
*/
static Client client;
/**
* 播放声音
*/
private AudioPlay aplay = new AudioPlay();
javax.swing.Timer time;
/**
* 启动客服端与服务器建立连接
*/
MainFrame frame;
// Server Fileserver;
public void init() {
try {
frame=new MainFrame();
String ip = "127.0.0.1";
int portInt = 8888;
// String port = "8888";
// ip = JOptionPane.showInputDialog("请输入服务器IP", "127.0.0.1");
// port = JOptionPane.showInputDialog("请输入服务器端口", 8888);
// int portInt = Integer.parseInt(port);
socket = new Socket(ip, portInt);
loginui = new LoginUI();
loginui.getJFrame();
// port1 = socket.getLocalPort();
netOut = new ObjectOutputStream(socket.getOutputStream());
netIn = new ObjectInputStream(socket.getInputStream());
receive();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "网络异常,连接服务端失败", "提示", 1);
System.exit(0);
}
}
/**
* 把对象输出网络
*/
public void send(Embody objMessage) {
try {
netOut.writeObject(objMessage);
netOut.flush();
} catch (Exception e) {
System.out.println("网络输出异常" + e.getMessage());
}
}
/**
* 从网络接收对象
*/
public void receive() {
Embody objMsg = new Embody();
while (runFlag) {
try {
if ((objMsg = (Embody) netIn.readObject()) != null) {
chatProtocol(objMsg);
}
} catch (IOException e) {
System.out.println("网络接收异常" + e.getMessage());
} catch (ClassNotFoundException e) {
System.out.println("找不到这个类" + e.getMessage());
} catch (Exception e) {
System.out.println("未知异常" + e.getMessage());
}
}
}
/**
* 响应ClientMainUI的喇叭事件 接收到系统消息后
*/
public void acceptOrder() {
Client.hidden = false;
this.msgShandong(hidden);
}
/**
* 信令接收的全部方法
*/
@SuppressWarnings("unchecked")
public void chatProtocol(Embody objMsg) throws IOException, ClassNotFoundException {
this.loginOrderRecieve(objMsg);
this.regOrderRecieve(objMsg);
this.reicievModifyUserInfo(objMsg);
this.chatMsgRecieve(objMsg);
this.inchatReceieve(objMsg);
this.delFriendOrderRecieve(objMsg);
this.addfriendfailInfoOder(objMsg);
this.checkFriendInfoOrderRecieve(objMsg);
this.checkfriendIPReceive(objMsg);
this.checkfriendportReceive(objMsg);
if (objMsg.getOrder().equals(setting.Command.addfriendqueren)
|| objMsg.getOrder().equals(setting.Command.addfriendtongyi)
|| objMsg.getOrder().equals(setting.Command.addfriendbutongyi)) {
aplay.soundPlay("/music/kesou.wav");
orderSys.add(objMsg.getOrder());// 将收来的信令保存
hidden = true;// 收到信令就开始闪动
this.msgShandong(hidden);
if (!this.msgShandong(hidden)) {
acceptorder = true;
}
}
if (objMsg.getOrder().equals(setting.Command.addfriendaginqueren)) {
orderSys.add(objMsg.getOrder());// 将收来的信令保存
acceptorder = true;
}
if (objMsg.getOrder().equals(setting.Command.friendliveline)) {
this.friendlogoutOrderRecieve(objMsg);
}
while (Client.acceptorder) {
for (int i = 0; i < orderSys.size(); i++) {
ordersave = (String) orderSys.elementAt(i);
objMsg.setOrder(ordersave);
orderSys.removeElementAt(i);// 删除已发信令
this.addFriendOrderRecieve(objMsg);
Client.acceptorder = false;
}
}
}
/**
* ClientMainUI中头像是否闪动
*/
public void run() {
Client.mainUI.getJLabel().setVisible(false);
}
public boolean msgShandong(boolean hidden) {
while (Client.hidden) {
for (int i = 0;; i = i + 5) {
if (i % 2 == 0) {
Client.mainUI.getJLabel().setVisible(false);
}
if (i % 2 == 1) {
Client.mainUI.getJLabel().setVisible(true);
}
if (!Client.hidden) {
Client.mainUI.getJLabel().setVisible(true);
break;
}
}
}
return hidden;
}
/**
* 接收注册信令
*/
public void regOrderRecieve(Embody objMsg)// 注册信令
{
String order = objMsg.getOrder();
if (order.equals(setting.Command.regi
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
修复了上个资源中的多个缺陷http://download.csdn.net/source/1675186 添加了文件传输功能,修改了部分功能。基于JavaSE开发的即时通信软件,附可执行打包文件。采用C/S设计模式,服务端使用数据库文件,无需设计数据库方便实用。源代码来源于网络,修改了源代码中错误若干,修复BUG若干。
资源推荐
资源详情
资源评论
收起资源包目录
Java即时通信软件源代码 (259个子文件)
all-wcprops 3KB
all-wcprops 903B
all-wcprops 738B
all-wcprops 681B
all-wcprops 674B
all-wcprops 667B
all-wcprops 656B
all-wcprops 579B
all-wcprops 551B
all-wcprops 506B
all-wcprops 240B
all-wcprops 102B
all-wcprops 101B
all-wcprops 88B
all-wcprops 87B
Client.class 21KB
SocketThread.class 10KB
ServerUI.class 10KB
Serve.class 10KB
Work.class 9KB
UserRegUI.class 8KB
ModifyUserUI.class 7KB
ChatUI1.class 7KB
LoginUI.class 6KB
TransFileManager.class 6KB
FriendTree.class 5KB
ClientMainUI.class 5KB
ChatUI.class 5KB
MainFrame.class 5KB
User.class 4KB
User.class 4KB
Chatrecord.class 4KB
InchatverUI.class 4KB
InchatarrivUI.class 4KB
InchatUI.class 4KB
TransFilePanel.class 4KB
FriendTree$1.class 3KB
Command.class 3KB
Command.class 3KB
ChatUI$2.class 2KB
ItemListenerimp.class 2KB
ChatUI$3.class 2KB
Server.class 2KB
Chatrecord$2.class 2KB
Embody.class 2KB
Embody.class 2KB
ChatUI$1.class 2KB
JTreeBean.class 2KB
InchatUI$3.class 2KB
JTreeCellRenderer.class 2KB
ServerUI$4.class 1KB
InchatarrivUI$2.class 1KB
AudioPlay.class 1004B
ClientMainUI$1.class 941B
Chatrecord$3.class 925B
ServerUI$3.class 920B
InchatUI$2.class 913B
ChatUI$4.class 901B
InchatarrivUI$1.class 776B
UserInfoAndThread.class 772B
Chatrecord$1.class 769B
InchatUI$1.class 746B
ServerUI$2.class 746B
ServerUI$1.class 746B
ChatUI1$2.class 737B
ChatUI1$1.class 737B
TransFilePanel_jbtnCannel_actionAdapter.class 721B
TransFilePanel_jbtnOK_actionAdapter.class 709B
UserRegUI$1.class 706B
LoginUI$1.class 694B
MainFrame_jbtnSend_actionAdapter.class 685B
InchatverUI$1.class 664B
MainFrame_this_windowAdapter.class 642B
ChatUI1$3.class 531B
dir-prop-base 37B
dir-prop-base 37B
dir-prop-base 33B
dir-prop-base 33B
entries 3KB
entries 1KB
entries 1KB
entries 1KB
entries 967B
entries 921B
entries 893B
entries 880B
entries 858B
entries 720B
entries 429B
entries 307B
entries 301B
entries 267B
entries 246B
ChatUI1.form 12KB
format 2B
format 2B
format 2B
format 2B
format 2B
format 2B
共 259 条
- 1
- 2
- 3
weiqixuan1111
- 粉丝: 14
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页