├── bin
├── server.bat
├── client.bat
├── badword.txt
├── face
│ ├── face.ini
│ ├── 1.JPG
│ ├── 2.JPG
│ ├── 3.JPG
│ └── Thumbs.db
├── CLOCK.ICO
├── HaHa.ico
├── user.txt
├── user2.txt
├── Chat.class
├── Clock.class
├── Exit.class
├── Login.class
├── ChatRoom.class
├── Clock$1.class
├── Customer.class
├── Message.class
├── Register.class
├── message.txt
├── AppServer.class
├── ChatClient.class
├── ChatRoom$1.class
├── ChatRoom$2.class
├── ChatRoom$3.class
├── ChatRoom$4.class
├── ChatRoom$5.class
├── ChatRoom$6.class
├── ChatRoom$7.class
├── Connection.class
├── Register$1.class
├── ServerFrame.class
├── WordFilter.class
├── images
│ ├── CLOCK.ICO
│ ├── Thumbs.db
│ ├── appico.jpg
│ ├── chat.jpg
│ ├── login.gif
│ ├── btnClock.jpg
│ ├── btnExit.jpg
│ ├── btnLogin.jpg
│ ├── register.jpg
│ ├── serverip.gif
│ ├── btnCancel.jpg
│ ├── btnRegister.jpg
│ ├── loginlogo.jpg
│ ├── from-download.gif
│ └── registerlogo.jpg
├── ServerFrame$1.class
├── ServerFrame$2.class
├── ServerFrame$3.class
├── ServerFrame$4.class
├── Champicons Icon 19.ico
├── Register_Customer.class
├── ChatRoom$Windowclose.class
├── aaa_message.txt
├── ccc_message.txt
├── log.txt
└── HeadFile.properties
├── src
├── server.bat
├── client.bat
├── badword.txt
├── face
│ ├── face.ini
│ ├── 1.JPG
│ ├── 2.JPG
│ ├── 3.JPG
│ └── Thumbs.db
├── CLOCK.ICO
├── HaHa.ico
├── user.txt
├── user2.txt
├── message.txt
├── images
│ ├── CLOCK.ICO
│ ├── Thumbs.db
│ ├── appico.jpg
│ ├── chat.jpg
│ ├── login.gif
│ ├── btnClock.jpg
│ ├── btnExit.jpg
│ ├── btnLogin.jpg
│ ├── register.jpg
│ ├── serverip.gif
│ ├── btnCancel.jpg
│ ├── btnRegister.jpg
│ ├── loginlogo.jpg
│ ├── from-download.gif
│ └── registerlogo.jpg
├── Champicons Icon 19.ico
├── Exit.java
├── Customer.java
├── ChatClient.java
├── aaa_message.txt
├── Message.java
├── ccc_message.txt
├── Register_Customer.java
├── log.txt
├── Chat.java
├── HeadFile.properties
├── AppServer.java
├── WordFilter.java
├── Clock.java
├── Login.java
├── Register.java
├── ServerFrame.java
├── Connection.java
└── ChatRoom.java
├── user.txt
├── .classpath
├── .project
└── .settings
└── org.eclipse.jdt.core.prefs
/bin/server.bat:
--------------------------------------------------------------------------------
1 | java AppServer
--------------------------------------------------------------------------------
/src/server.bat:
--------------------------------------------------------------------------------
1 | java AppServer
--------------------------------------------------------------------------------
/bin/client.bat:
--------------------------------------------------------------------------------
1 | java ChatClient
--------------------------------------------------------------------------------
/src/client.bat:
--------------------------------------------------------------------------------
1 | java ChatClient
--------------------------------------------------------------------------------
/bin/badword.txt:
--------------------------------------------------------------------------------
1 | 陈敏,胡锦涛,江泽民,
2 | ss,sex,xxx
3 |
--------------------------------------------------------------------------------
/src/badword.txt:
--------------------------------------------------------------------------------
1 | 陈敏,胡锦涛,江泽民,
2 | ss,sex,xxx
3 |
--------------------------------------------------------------------------------
/bin/face/face.ini:
--------------------------------------------------------------------------------
1 | [MAIN]
2 | MAXFACE=100
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/face/face.ini:
--------------------------------------------------------------------------------
1 | [MAIN]
2 | MAXFACE=100
3 |
4 |
5 |
--------------------------------------------------------------------------------
/user.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/user.txt
--------------------------------------------------------------------------------
/bin/CLOCK.ICO:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/CLOCK.ICO
--------------------------------------------------------------------------------
/bin/HaHa.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/HaHa.ico
--------------------------------------------------------------------------------
/bin/user.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/user.txt
--------------------------------------------------------------------------------
/bin/user2.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/user2.txt
--------------------------------------------------------------------------------
/src/CLOCK.ICO:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/CLOCK.ICO
--------------------------------------------------------------------------------
/src/HaHa.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/HaHa.ico
--------------------------------------------------------------------------------
/src/user.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/user.txt
--------------------------------------------------------------------------------
/src/user2.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/user2.txt
--------------------------------------------------------------------------------
/bin/Chat.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/Chat.class
--------------------------------------------------------------------------------
/bin/Clock.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/Clock.class
--------------------------------------------------------------------------------
/bin/Exit.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/Exit.class
--------------------------------------------------------------------------------
/bin/Login.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/Login.class
--------------------------------------------------------------------------------
/bin/face/1.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/face/1.JPG
--------------------------------------------------------------------------------
/bin/face/2.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/face/2.JPG
--------------------------------------------------------------------------------
/bin/face/3.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/face/3.JPG
--------------------------------------------------------------------------------
/src/face/1.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/face/1.JPG
--------------------------------------------------------------------------------
/src/face/2.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/face/2.JPG
--------------------------------------------------------------------------------
/src/face/3.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/face/3.JPG
--------------------------------------------------------------------------------
/bin/ChatRoom.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ChatRoom.class
--------------------------------------------------------------------------------
/bin/Clock$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/Clock$1.class
--------------------------------------------------------------------------------
/bin/Customer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/Customer.class
--------------------------------------------------------------------------------
/bin/Message.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/Message.class
--------------------------------------------------------------------------------
/bin/Register.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/Register.class
--------------------------------------------------------------------------------
/bin/face/Thumbs.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/face/Thumbs.db
--------------------------------------------------------------------------------
/bin/message.txt:
--------------------------------------------------------------------------------
1 | 【你】对【bbb】说:efvrev
2 | 【aaa】来了
3 | 【你】对【所有人】说:dddd
4 | 【你】对【所有人】说:dwqda
5 |
--------------------------------------------------------------------------------
/src/face/Thumbs.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/face/Thumbs.db
--------------------------------------------------------------------------------
/src/message.txt:
--------------------------------------------------------------------------------
1 | 【你】对【bbb】说:efvrev
2 | 【aaa】来了
3 | 【你】对【所有人】说:dddd
4 | 【你】对【所有人】说:dwqda
5 |
--------------------------------------------------------------------------------
/bin/AppServer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/AppServer.class
--------------------------------------------------------------------------------
/bin/ChatClient.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ChatClient.class
--------------------------------------------------------------------------------
/bin/ChatRoom$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ChatRoom$1.class
--------------------------------------------------------------------------------
/bin/ChatRoom$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ChatRoom$2.class
--------------------------------------------------------------------------------
/bin/ChatRoom$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ChatRoom$3.class
--------------------------------------------------------------------------------
/bin/ChatRoom$4.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ChatRoom$4.class
--------------------------------------------------------------------------------
/bin/ChatRoom$5.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ChatRoom$5.class
--------------------------------------------------------------------------------
/bin/ChatRoom$6.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ChatRoom$6.class
--------------------------------------------------------------------------------
/bin/ChatRoom$7.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ChatRoom$7.class
--------------------------------------------------------------------------------
/bin/Connection.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/Connection.class
--------------------------------------------------------------------------------
/bin/Register$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/Register$1.class
--------------------------------------------------------------------------------
/bin/ServerFrame.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ServerFrame.class
--------------------------------------------------------------------------------
/bin/WordFilter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/WordFilter.class
--------------------------------------------------------------------------------
/bin/images/CLOCK.ICO:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/CLOCK.ICO
--------------------------------------------------------------------------------
/bin/images/Thumbs.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/Thumbs.db
--------------------------------------------------------------------------------
/bin/images/appico.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/appico.jpg
--------------------------------------------------------------------------------
/bin/images/chat.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/chat.jpg
--------------------------------------------------------------------------------
/bin/images/login.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/login.gif
--------------------------------------------------------------------------------
/src/images/CLOCK.ICO:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/CLOCK.ICO
--------------------------------------------------------------------------------
/src/images/Thumbs.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/Thumbs.db
--------------------------------------------------------------------------------
/src/images/appico.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/appico.jpg
--------------------------------------------------------------------------------
/src/images/chat.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/chat.jpg
--------------------------------------------------------------------------------
/src/images/login.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/login.gif
--------------------------------------------------------------------------------
/bin/ServerFrame$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ServerFrame$1.class
--------------------------------------------------------------------------------
/bin/ServerFrame$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ServerFrame$2.class
--------------------------------------------------------------------------------
/bin/ServerFrame$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ServerFrame$3.class
--------------------------------------------------------------------------------
/bin/ServerFrame$4.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ServerFrame$4.class
--------------------------------------------------------------------------------
/bin/images/btnClock.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/btnClock.jpg
--------------------------------------------------------------------------------
/bin/images/btnExit.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/btnExit.jpg
--------------------------------------------------------------------------------
/bin/images/btnLogin.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/btnLogin.jpg
--------------------------------------------------------------------------------
/bin/images/register.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/register.jpg
--------------------------------------------------------------------------------
/bin/images/serverip.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/serverip.gif
--------------------------------------------------------------------------------
/src/images/btnClock.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/btnClock.jpg
--------------------------------------------------------------------------------
/src/images/btnExit.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/btnExit.jpg
--------------------------------------------------------------------------------
/src/images/btnLogin.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/btnLogin.jpg
--------------------------------------------------------------------------------
/src/images/register.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/register.jpg
--------------------------------------------------------------------------------
/src/images/serverip.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/serverip.gif
--------------------------------------------------------------------------------
/bin/Champicons Icon 19.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/Champicons Icon 19.ico
--------------------------------------------------------------------------------
/bin/images/btnCancel.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/btnCancel.jpg
--------------------------------------------------------------------------------
/bin/images/btnRegister.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/btnRegister.jpg
--------------------------------------------------------------------------------
/bin/images/loginlogo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/loginlogo.jpg
--------------------------------------------------------------------------------
/src/Champicons Icon 19.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/Champicons Icon 19.ico
--------------------------------------------------------------------------------
/src/images/btnCancel.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/btnCancel.jpg
--------------------------------------------------------------------------------
/src/images/btnRegister.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/btnRegister.jpg
--------------------------------------------------------------------------------
/src/images/loginlogo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/loginlogo.jpg
--------------------------------------------------------------------------------
/bin/Register_Customer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/Register_Customer.class
--------------------------------------------------------------------------------
/bin/images/from-download.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/from-download.gif
--------------------------------------------------------------------------------
/bin/images/registerlogo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/images/registerlogo.jpg
--------------------------------------------------------------------------------
/src/images/from-download.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/from-download.gif
--------------------------------------------------------------------------------
/src/images/registerlogo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/src/images/registerlogo.jpg
--------------------------------------------------------------------------------
/bin/ChatRoom$Windowclose.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shaweiwei/happy-chat/HEAD/bin/ChatRoom$Windowclose.class
--------------------------------------------------------------------------------
/src/Exit.java:
--------------------------------------------------------------------------------
1 |
2 | import java.io.Serializable;
3 |
4 | public class Exit implements Serializable {
5 |
6 | private static final long serialVersionUID = -5267537916643834426L;
7 | /**
8 | * 退出者用户名
9 | */
10 | public String exitname;
11 | }
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
Title:HappyChat聊天系统客户端程序
3 | *Description:客户端主程序
4 | *Copyright:Copyright (C)2006
5 | *Filename:ChatClient.java
6 | *@author 刘志成 7 | *@version 1.0 8 | */ 9 | 10 | /////////////////////////////////// 11 | //////////设置服务器IP地址///////// 12 | /////////////////////////////////// 13 | public class ChatClient { 14 | 15 | public ChatClient() { 16 | } 17 | 18 | public static void main(String args[]) { 19 | new Login(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /bin/aaa_message.txt: -------------------------------------------------------------------------------- 1 | 【ccc】来了 2 | 【ccc】对【所有人】说:ccccewefwefwe 3 | 【ccc】对【所有人】说:wefwefwfwf 4 | 【ccc】对【所有人】说:fewewfwef 5 | 【你】对【所有人】说:fewfewf 6 | 【你】对【ccc】说:fewfwefe 7 | 【你】对【ccc】说:efwfwe 8 | 【ccc】对【你】说:dsvvgsdgsg 9 | 【ccc】对【你】说:sdfsdgsdgsg 10 | 【ccc】来了 11 | 【ccc】对【所有人】说:wewdwed 12 | 【ccc】对【所有人】说:wdewe 13 | 【ccc】对【所有人】说:wedwe 14 | 【ccc】对【所有人】说:wewde 15 | 【ccc】对【所有人】说:wdwdewd 16 | 【ccc】对【所有人】说:wdewd 17 | 【ccc】对【你】惊喜地说:esdgse 18 | 【ccc】对【你】惊喜地说: 19 | 【ccc】对【你】惊喜地说:efwefwef 20 | 【ccc】对【你】惊喜地说:fewfewfwegweg 21 | 【你】对【所有人】说:rwqtw3etgweygwye -------------------------------------------------------------------------------- /src/aaa_message.txt: -------------------------------------------------------------------------------- 1 | 【ccc】来了 2 | 【ccc】对【所有人】说:ccccewefwefwe 3 | 【ccc】对【所有人】说:wefwefwfwf 4 | 【ccc】对【所有人】说:fewewfwef 5 | 【你】对【所有人】说:fewfewf 6 | 【你】对【ccc】说:fewfwefe 7 | 【你】对【ccc】说:efwfwe 8 | 【ccc】对【你】说:dsvvgsdgsg 9 | 【ccc】对【你】说:sdfsdgsdgsg 10 | 【ccc】来了 11 | 【ccc】对【所有人】说:wewdwed 12 | 【ccc】对【所有人】说:wdewe 13 | 【ccc】对【所有人】说:wedwe 14 | 【ccc】对【所有人】说:wewde 15 | 【ccc】对【所有人】说:wdwdewd 16 | 【ccc】对【所有人】说:wdewd 17 | 【ccc】对【你】惊喜地说:esdgse 18 | 【ccc】对【你】惊喜地说: 19 | 【ccc】对【你】惊喜地说:efwefwef 20 | 【ccc】对【你】惊喜地说:fewfewfwegweg 21 | 【你】对【所有人】说:rwqtw3etgweygwye -------------------------------------------------------------------------------- /src/Message.java: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import java.util.Vector; 3 | 4 | public class Message implements Serializable { 5 | 6 | private static final long serialVersionUID = -3831507106408529855L; 7 | 8 | /** 9 | * 用户在线对象集 10 | */ 11 | public Vector userOnLine; 12 | 13 | /** 14 | * 聊天信息集 15 | */ 16 | 17 | public Vector chat; 18 | 19 | /** 20 | * 被踢者姓名 21 | */ 22 | 23 | public String ti; 24 | 25 | /** 26 | * 公告 27 | */ 28 | 29 | public String serverMessage; 30 | 31 | } -------------------------------------------------------------------------------- /bin/ccc_message.txt: -------------------------------------------------------------------------------- 1 | 【你】对【所有人】说:ccccewefwefwe 2 | 【你】对【所有人】说:wefwefwfwf 3 | 【你】对【所有人】说:fewewfwef 4 | 【aaa】对【所有人】说:fewfewf 5 | 【aaa】对【你】说:fewfwefe 6 | 【aaa】对【你】说:efwfwe 7 | 【你】对【aaa】说:dsvvgsdgsg 8 | 【你】对【aaa】说:sdfsdgsdgsg 9 | 【你】对【aaa】惊喜地说:efwefwef 10 | 【你】对【aaa】惊喜地说:fewfewfwegweg 11 | 【aaa】对【所有人】说:rwqtw3etgweygwye 12 | 【bbb】对【所有人】甜笑地说:hello 13 | 【你】对【aaa】说:sdSADASDASDF 14 | 【你】对【aaa】说:SSS 15 | 【你】对【aaa】说:非法内容,系统屏蔽 16 | 【你】对【aaa】说:sas 17 | 【你】对【aaa】说:非法内容,系统屏蔽 18 | 【你】对【aaa】说:s e x 19 | 【你】对【aaa】甜笑地说:dfad 20 | 【你】对【aaa】嘻嘻地说: 21 | 【你】对【aaa】嘻嘻地说: 22 | -------------------------------------------------------------------------------- /src/ccc_message.txt: -------------------------------------------------------------------------------- 1 | 【你】对【所有人】说:ccccewefwefwe 2 | 【你】对【所有人】说:wefwefwfwf 3 | 【你】对【所有人】说:fewewfwef 4 | 【aaa】对【所有人】说:fewfewf 5 | 【aaa】对【你】说:fewfwefe 6 | 【aaa】对【你】说:efwfwe 7 | 【你】对【aaa】说:dsvvgsdgsg 8 | 【你】对【aaa】说:sdfsdgsdgsg 9 | 【你】对【aaa】惊喜地说:efwefwef 10 | 【你】对【aaa】惊喜地说:fewfewfwegweg 11 | 【aaa】对【所有人】说:rwqtw3etgweygwye 12 | 【bbb】对【所有人】甜笑地说:hello 13 | 【你】对【aaa】说:sdSADASDASDF 14 | 【你】对【aaa】说:SSS 15 | 【你】对【aaa】说:非法内容,系统屏蔽 16 | 【你】对【aaa】说:sas 17 | 【你】对【aaa】说:非法内容,系统屏蔽 18 | 【你】对【aaa】说:s e x 19 | 【你】对【aaa】甜笑地说:dfad 20 | 【你】对【aaa】嘻嘻地说: 21 | 【你】对【aaa】嘻嘻地说: 22 | -------------------------------------------------------------------------------- /src/Register_Customer.java: -------------------------------------------------------------------------------- 1 | 2 | public class Register_Customer extends Object implements java.io.Serializable { 3 | 4 | private static final long serialVersionUID = 7116984729771538742L; 5 | /** 6 | * 姓名 7 | */ 8 | public String custName; 9 | /** 10 | * 密码 11 | */ 12 | public String custPassword; 13 | /** 14 | * 年龄 15 | */ 16 | public String age; 17 | /** 18 | * 性别 19 | */ 20 | public String sex; 21 | /** 22 | * 电子邮件 23 | */ 24 | public String email; 25 | /** 26 | * 头像文件名 27 | */ 28 | public String head; 29 | 30 | } -------------------------------------------------------------------------------- /bin/log.txt: -------------------------------------------------------------------------------- 1 | 2 | [21:27:59]ccc->所有人:ccccewefwefwe 3 | [21:28:2]ccc->所有人:wefwefwfwf 4 | [21:28:11]ccc->所有人:fewewfwef 5 | [21:28:13]aaa->所有人:fewfewf 6 | [21:28:19]aaa->ccc:fewfwefe 7 | [21:28:23]aaa->ccc:efwfwe 8 | [21:28:29]ccc->aaa:dsvvgsdgsg 9 | [21:28:32]ccc->aaa:sdfsdgsdgsg 10 | [21:31:50]ccc->所有人:wewdwed 11 | [21:32:19]ccc->所有人:wdewe 12 | [21:32:29]ccc->所有人:wedwe 13 | [21:32:42]ccc->所有人:wewde 14 | [21:32:54]ccc->所有人:wdwdewd 15 | [21:33:1]ccc->所有人:wdewd 16 | [21:34:22]ccc->aaa:esdgse 17 | [21:34:22]ccc->aaa: 18 | [21:34:27]ccc->aaa:efwefwef 19 | [21:34:30]ccc->aaa:fewfewfwegweg 20 | [21:34:36]aaa->所有人:rwqtw3etgweygwye -------------------------------------------------------------------------------- /src/log.txt: -------------------------------------------------------------------------------- 1 | 2 | [21:27:59]ccc->所有人:ccccewefwefwe 3 | [21:28:2]ccc->所有人:wefwefwfwf 4 | [21:28:11]ccc->所有人:fewewfwef 5 | [21:28:13]aaa->所有人:fewfewf 6 | [21:28:19]aaa->ccc:fewfwefe 7 | [21:28:23]aaa->ccc:efwfwe 8 | [21:28:29]ccc->aaa:dsvvgsdgsg 9 | [21:28:32]ccc->aaa:sdfsdgsdgsg 10 | [21:31:50]ccc->所有人:wewdwed 11 | [21:32:19]ccc->所有人:wdewe 12 | [21:32:29]ccc->所有人:wedwe 13 | [21:32:42]ccc->所有人:wewde 14 | [21:32:54]ccc->所有人:wdwdewd 15 | [21:33:1]ccc->所有人:wdewd 16 | [21:34:22]ccc->aaa:esdgse 17 | [21:34:22]ccc->aaa: 18 | [21:34:27]ccc->aaa:efwefwef 19 | [21:34:30]ccc->aaa:fewfewfwegweg 20 | [21:34:36]aaa->所有人:rwqtw3etgweygwye -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.8 12 | -------------------------------------------------------------------------------- /src/Chat.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.Serializable; 3 | 4 | /** 5 | *6 | * Title: HappyChat聊天系统登录程序 7 | *
8 | *9 | * Description: 聊天内容对象 10 | *
11 | *12 | * Copyright: Copyright (c) 2006 13 | *
14 | *15 | * Filename: Chat.java 16 | *
17 | * 18 | * @author ***** 19 | * @version 1.0 20 | */ 21 | public class Chat implements Serializable { 22 | 23 | private static final long serialVersionUID = 4058485121419391969L; 24 | /** 25 | * 发言人用户名 26 | */ 27 | public String chatUser; 28 | /** 29 | * 聊天内容 30 | */ 31 | public String chatMessage; 32 | /** 33 | * 接受对象用户名 34 | */ 35 | public String chatToUser; 36 | /** 37 | * 聊天语气 38 | */ 39 | public String emote; 40 | /** 41 | * 是否私聊 42 | */ 43 | public boolean whisper; 44 | } -------------------------------------------------------------------------------- /bin/HeadFile.properties: -------------------------------------------------------------------------------- 1 | #Chenmin Write! 2 | #Sun Feb 29 17:41:08 CST 2004 3 | 59=59.bmp 4 | 58=58.bmp 5 | 57=57.bmp 6 | 56=56.bmp 7 | 55=55.bmp 8 | 54=54.bmp 9 | 53=53.bmp 10 | 52=52.bmp 11 | 51=51.bmp 12 | 50=50.bmp 13 | 49=49.bmp 14 | 48=48.bmp 15 | 47=47.bmp 16 | 46=46.bmp 17 | 45=45.bmp 18 | 44=44.bmp 19 | 43=43.bmp 20 | 42=42.bmp 21 | 41=41.bmp 22 | 40=40.bmp 23 | 100=100.bmp 24 | 39=39.bmp 25 | 38=38.bmp 26 | 37=37.bmp 27 | 36=36.bmp 28 | 35=35.bmp 29 | 99=99.bmp 30 | 34=34.bmp 31 | 98=98.bmp 32 | 33=33.bmp 33 | 97=97.bmp 34 | 32=32.bmp 35 | 96=96.bmp 36 | 31=31.bmp 37 | 95=95.bmp 38 | 30=30.bmp 39 | 94=94.bmp 40 | 93=93.bmp 41 | 92=92.bmp 42 | 91=91.bmp 43 | 90=90.bmp 44 | 29=29.bmp 45 | 28=28.bmp 46 | 27=27.bmp 47 | 26=26.bmp 48 | 25=25.bmp 49 | 89=89.bmp 50 | 24=24.bmp 51 | 88=88.bmp 52 | 23=23.bmp 53 | 87=87.bmp 54 | 22=22.bmp 55 | 86=86.bmp 56 | 21=21.bmp 57 | 85=85.bmp 58 | 20=20.bmp 59 | 84=84.bmp 60 | 83=83.bmp 61 | 82=82.bmp 62 | 81=81.bmp 63 | 80=80.bmp 64 | 9=9.bmp 65 | 8=8.bmp 66 | 7=7.bmp 67 | 6=6.bmp 68 | 5=5.bmp 69 | 4=4.bmp 70 | 3=3.bmp 71 | 2=2.bmp 72 | 1=1.bmp 73 | 0=0.bmp 74 | 19=19.bmp 75 | 18=18.bmp 76 | 17=17.bmp 77 | 16=16.bmp 78 | 15=15.bmp 79 | 79=79.bmp 80 | 14=14.bmp 81 | 78=78.bmp 82 | 13=13.bmp 83 | 77=77.bmp 84 | 12=12.bmp 85 | 76=76.bmp 86 | 11=11.bmp 87 | 75=75.bmp 88 | 10=10.bmp 89 | 74=74.bmp 90 | 73=73.bmp 91 | 72=72.bmp 92 | 71=71.bmp 93 | 70=70.bmp 94 | 69=69.bmp 95 | 68=68.bmp 96 | 67=67.bmp 97 | 66=66.bmp 98 | 65=65.bmp 99 | 64=64.bmp 100 | 63=63.bmp 101 | 62=62.bmp 102 | 61=61.bmp 103 | 60=60.bmp 104 | -------------------------------------------------------------------------------- /src/HeadFile.properties: -------------------------------------------------------------------------------- 1 | #Chenmin Write! 2 | #Sun Feb 29 17:41:08 CST 2004 3 | 59=59.bmp 4 | 58=58.bmp 5 | 57=57.bmp 6 | 56=56.bmp 7 | 55=55.bmp 8 | 54=54.bmp 9 | 53=53.bmp 10 | 52=52.bmp 11 | 51=51.bmp 12 | 50=50.bmp 13 | 49=49.bmp 14 | 48=48.bmp 15 | 47=47.bmp 16 | 46=46.bmp 17 | 45=45.bmp 18 | 44=44.bmp 19 | 43=43.bmp 20 | 42=42.bmp 21 | 41=41.bmp 22 | 40=40.bmp 23 | 100=100.bmp 24 | 39=39.bmp 25 | 38=38.bmp 26 | 37=37.bmp 27 | 36=36.bmp 28 | 35=35.bmp 29 | 99=99.bmp 30 | 34=34.bmp 31 | 98=98.bmp 32 | 33=33.bmp 33 | 97=97.bmp 34 | 32=32.bmp 35 | 96=96.bmp 36 | 31=31.bmp 37 | 95=95.bmp 38 | 30=30.bmp 39 | 94=94.bmp 40 | 93=93.bmp 41 | 92=92.bmp 42 | 91=91.bmp 43 | 90=90.bmp 44 | 29=29.bmp 45 | 28=28.bmp 46 | 27=27.bmp 47 | 26=26.bmp 48 | 25=25.bmp 49 | 89=89.bmp 50 | 24=24.bmp 51 | 88=88.bmp 52 | 23=23.bmp 53 | 87=87.bmp 54 | 22=22.bmp 55 | 86=86.bmp 56 | 21=21.bmp 57 | 85=85.bmp 58 | 20=20.bmp 59 | 84=84.bmp 60 | 83=83.bmp 61 | 82=82.bmp 62 | 81=81.bmp 63 | 80=80.bmp 64 | 9=9.bmp 65 | 8=8.bmp 66 | 7=7.bmp 67 | 6=6.bmp 68 | 5=5.bmp 69 | 4=4.bmp 70 | 3=3.bmp 71 | 2=2.bmp 72 | 1=1.bmp 73 | 0=0.bmp 74 | 19=19.bmp 75 | 18=18.bmp 76 | 17=17.bmp 77 | 16=16.bmp 78 | 15=15.bmp 79 | 79=79.bmp 80 | 14=14.bmp 81 | 78=78.bmp 82 | 13=13.bmp 83 | 77=77.bmp 84 | 12=12.bmp 85 | 76=76.bmp 86 | 11=11.bmp 87 | 75=75.bmp 88 | 10=10.bmp 89 | 74=74.bmp 90 | 73=73.bmp 91 | 72=72.bmp 92 | 71=71.bmp 93 | 70=70.bmp 94 | 69=69.bmp 95 | 68=68.bmp 96 | 67=67.bmp 97 | 66=66.bmp 98 | 65=65.bmp 99 | 64=64.bmp 100 | 63=63.bmp 101 | 62=62.bmp 102 | 61=61.bmp 103 | 60=60.bmp 104 | -------------------------------------------------------------------------------- /src/AppServer.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.net.*; 3 | import java.util.*; 4 | 5 | /** 6 | *7 | * Title: HappyChat聊天系统服务器程序 8 | *
9 | *10 | * Description: 聊天服务器 11 | *
12 | *13 | * Copyright: Copyright (c) 2006 14 | *
15 | *16 | * Filename: AppServer.java 17 | *
18 | * 创建服务器9 | * Title: HappyChat聊天系统登录程序 10 | *
11 | *12 | * Description: 过滤用户聊天内容 13 | *
14 | *15 | * Copyright: Copyright (c) 2006 16 | *
17 | *18 | * Filename: WordFilter.java 19 | *
20 | * 21 | * @author ***** 22 | * @version 1.0 23 | */ 24 | public class WordFilter { 25 | 26 | /** 27 | * 准备过滤的内容 28 | */ 29 | private String word = ""; 30 | 31 | /** 32 | * 得到过滤的内容 33 | * 34 | * @return 过滤的内容 35 | */ 36 | public String getWord() { 37 | return word; 38 | } 39 | 40 | /** 41 | * 设置过滤内容 42 | * 43 | * @param word 44 | * 过滤内容 45 | */ 46 | public void setWord(String word) { 47 | this.word = word; 48 | } 49 | 50 | /** 51 | * 设置过滤内容 52 | * 53 | * @param word 54 | * 过滤内容 55 | */ 56 | public WordFilter(String word) { 57 | super(); 58 | this.word = word; 59 | } 60 | 61 | /** 62 | * 创建过滤类 63 | * 64 | */ 65 | public WordFilter() { 66 | // TODO 自动生成构造函数存根 67 | } 68 | 69 | /** 70 | * 处理过滤内容 71 | * 72 | */ 73 | public void process() { 74 | String badWord = this.getFile("badword.txt"); 75 | // System.out.println(badWord); 76 | String badWordList[] = badWord.split(","); 77 | for (int i = 0; i < badWordList.length; i++) { 78 | // System.out.println(badWordList[i]); 79 | // System.out.println(badWordList[i]+":"+word.indexOf(badWordList[i])); 80 | if (word.indexOf(badWordList[i]) != -1) { 81 | word = "非法内容,系统屏蔽"; 82 | } 83 | } 84 | 85 | } 86 | 87 | /** 88 | * 得到过滤文件内容 89 | * 90 | * @param file 91 | * 过滤文件名 92 | * @return 过滤文件内容 93 | */ 94 | public String getFile(String file) { 95 | String fileString = ""; 96 | try { 97 | File files = new File(file); 98 | // System.out.println(files.getAbsolutePath()); 99 | FileReader fileReader = new FileReader(files); 100 | BufferedReader read = new BufferedReader(fileReader); 101 | while (true) { 102 | String line = read.readLine(); 103 | if (line == null) { 104 | break; 105 | } 106 | fileString += (line); 107 | // fileString += (line + "\n"); 108 | } 109 | read.close(); 110 | // System.out.println(fileString); 111 | } catch (FileNotFoundException e) { 112 | // TODO 自动生成 catch 块 113 | e.printStackTrace(); 114 | } catch (IOException e) { 115 | // TODO 自动生成 catch 块 116 | e.printStackTrace(); 117 | } 118 | 119 | return fileString; 120 | } 121 | 122 | /** 123 | * 过滤内容,返回合法内容 124 | * 125 | * @param word 126 | * 过滤内容 127 | * @return 合法内容 128 | */ 129 | public static String filter(String word) { 130 | WordFilter wf = new WordFilter(word); 131 | wf.process(); 132 | 133 | return wf.getWord(); 134 | 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/Clock.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import javax.swing.*; 3 | import java.awt.*; 4 | import java.awt.event.*; 5 | import javax.swing.Timer; 6 | 7 | public class Clock extends JFrame implements ActionListener { 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = 6790815213225162093L; 12 | Timer timer; 13 | int x, y, old_X, old_Y, r, x0, y0, w, h, ang; 14 | int sdo, mdo, hdo, old_M, old_H; 15 | TimeZone tz = TimeZone.getTimeZone("JST"); 16 | final double RAD = Math.PI / 180.0; 17 | 18 | @SuppressWarnings("deprecation") 19 | public Clock() { 20 | super("[HappyChat]时钟"); 21 | setSize(300, 300); 22 | setBackground(new Color(0, 0, 192)); 23 | setResizable(false); 24 | Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();// 在屏幕居中显示 25 | Dimension fra = this.getSize(); 26 | if (fra.width > scr.width) { 27 | fra.width = scr.width; 28 | } 29 | if (fra.height > scr.height) { 30 | fra.height = scr.height; 31 | } 32 | this.setLocation((scr.width - fra.width) / 2, (scr.height - fra.height) / 2); 33 | show(); 34 | int delay = 1000; 35 | 36 | // 窗体添加事件监听,监听秒表的触发 37 | ActionListener taskPerformer = new ActionListener() { 38 | public void actionPerformed(ActionEvent evt) { 39 | repaint(); 40 | } 41 | }; 42 | new Timer(delay, taskPerformer).start(); 43 | } 44 | 45 | public void actionPerformed(ActionEvent e) { 46 | timer.restart(); 47 | } 48 | 49 | public void paint(Graphics g) { 50 | Insets insets = getInsets(); 51 | int L0 = (insets.left) / 2, T0 = (insets.top) / 2; 52 | int hh, mm, ss; 53 | String st; 54 | h = getSize().height; 55 | // 绘制圆形 56 | g.setColor(Color.white); 57 | g.drawOval(L0 + 30, T0 + 30, h - 60, h - 60); 58 | g.drawOval(L0 + 32, T0 + 32, h - 64, h - 64); 59 | r = h / 2 - 30; 60 | x0 = 30 + r - 5 + L0; 61 | y0 = 30 + r - 5 - T0; 62 | ang = 60; 63 | for (int i = 1; i <= 12; i++) { 64 | x = (int) ((r + 10) * Math.cos(RAD * ang) + x0); 65 | y = (int) ((r + 10) * Math.sin(RAD * ang) + y0); 66 | g.drawString("" + i, x, h - y); 67 | ang -= 30; 68 | } 69 | x0 = 30 + r + L0; 70 | y0 = 30 + r + T0; 71 | // 获取时间 72 | Calendar now = Calendar.getInstance(); 73 | hh = now.get(Calendar.HOUR_OF_DAY);// 小时 74 | mm = now.get(Calendar.MINUTE);// 分钟 75 | ss = now.get(Calendar.SECOND);// 秒 76 | g.setColor(Color.pink); 77 | g.fillRect(L0, T0, 60, 28);// 填充的矩形 78 | g.setColor(Color.blue); 79 | if (hh < 10) 80 | st = "0" + hh; 81 | else 82 | st = "" + hh; 83 | if (mm < 10) 84 | st = st + ":0" + mm; 85 | else 86 | st = st + ":" + mm; 87 | if (ss < 10) 88 | st = st + ":0" + ss; 89 | else 90 | st = st + ":" + ss; 91 | g.drawString(st, L0, T0 + 25); 92 | // 计算时间和图形的关系 93 | sdo = 90 - ss * 6; 94 | mdo = 90 - mm * 6; 95 | hdo = 90 - hh * 30 - mm / 2; 96 | // 擦除秒针 97 | if (old_X > 0) { 98 | g.setColor(getBackground()); 99 | g.drawLine(x0, y0, old_X, (h - old_Y)); 100 | } else { 101 | old_M = mdo; 102 | old_H = hdo; 103 | } 104 | // 绘制秒针 105 | g.setColor(Color.yellow); 106 | x = (int) ((r - 8) * Math.cos(RAD * sdo) + x0); 107 | y = (int) ((r - 8) * Math.sin(RAD * sdo) + y0) - 2 * T0; 108 | g.drawLine(x0, y0, x, (h - y)); 109 | 110 | old_X = x; 111 | old_Y = y; 112 | // 擦除分针和时针 113 | if (mdo != old_M) { 114 | line(g, old_M, (int) (r * 0.7), getBackground()); 115 | old_M = mdo; 116 | } 117 | if (hdo != old_H) { 118 | line(g, old_H, (int) (r * 0.5), getBackground()); 119 | old_H = hdo; 120 | } 121 | // 绘制分针 122 | line(g, mdo, (int) (r * 0.7), Color.green); 123 | // 绘制时针 124 | line(g, hdo, (int) (r * 0.5), Color.red); 125 | } // end paint 126 | 127 | public void line(Graphics g, int t, int n, Color c) { 128 | int[] xp = new int[4]; 129 | int[] yp = new int[4]; 130 | xp[0] = x0; 131 | yp[0] = y0; 132 | xp[1] = (int) ((n - 10) * Math.cos(RAD * (t - 4)) + x0); 133 | yp[1] = h - (int) ((n - 10) * Math.sin(RAD * (t - 4)) + y0); 134 | xp[2] = (int) (n * Math.cos(RAD * t) + x0); 135 | yp[2] = h - (int) (n * Math.sin(RAD * t) + y0); 136 | xp[3] = (int) ((n - 10) * Math.cos(RAD * (t + 4)) + x0); 137 | yp[3] = h - (int) ((n - 10) * Math.sin(RAD * (t + 4)) + y0); 138 | g.setColor(c); 139 | g.fillPolygon(xp, yp, 4); 140 | } 141 | 142 | public static void main(String args[]) { 143 | new Clock(); 144 | } 145 | } -------------------------------------------------------------------------------- /src/Login.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | 3 | import java.awt.*; 4 | import java.awt.event.*; 5 | import java.net.*; 6 | import java.io.*; 7 | 8 | /** 9 | *10 | * Title: HappyChat聊天系统登录程序 11 | *
12 | *13 | * Description: 根据指定的服务器地址、用户名和密码登录聊天服务器 友情下载:http://www.codefans.net 14 | *
15 | *16 | * Copyright: Copyright (c) 2006 17 | *
18 | *19 | * Filename: Login.java 20 | *
21 | * 22 | * @author 刘志成 23 | * @version 1.0 24 | */ 25 | public class Login extends JFrame implements ActionListener { 26 | 27 | private static final long serialVersionUID = -8965773902056088264L; 28 | 29 | private JPanel pnlLogin; 30 | 31 | private JButton btnLogin, btnRegister, btnExit; 32 | 33 | private JLabel lblServer, lblUserName, lblPassword, lblLogo; 34 | 35 | private JTextField txtUserName, txtServer; 36 | 37 | private JPasswordField pwdPassword; 38 | 39 | private String strServerIp; 40 | 41 | // 用于将窗口定位 42 | private Dimension scrnsize; 43 | 44 | private Toolkit toolkit = Toolkit.getDefaultToolkit(); 45 | 46 | /** 47 | * 构造登陆窗体 48 | */ 49 | public Login() { 50 | super("登录[HappyChat]聊天室"); 51 | pnlLogin = new JPanel(); 52 | this.getContentPane().add(pnlLogin); 53 | 54 | lblServer = new JLabel("服务器(S):"); 55 | lblUserName = new JLabel("用户名(U):"); 56 | lblPassword = new JLabel("口 令(P):"); 57 | txtServer = new JTextField(20); 58 | txtServer.setText("127.0.0.1"); 59 | txtUserName = new JTextField(20); 60 | pwdPassword = new JPasswordField(20); 61 | btnLogin = new JButton("登录(L)"); 62 | btnLogin.setToolTipText("登录到服务器"); 63 | btnLogin.setMnemonic('L'); 64 | btnRegister = new JButton("注册(R)"); 65 | btnRegister.setToolTipText("注册新用户"); 66 | btnRegister.setMnemonic('R'); 67 | btnExit = new JButton("退出(X)"); 68 | btnExit.setToolTipText("退出系统"); 69 | btnExit.setMnemonic('X'); 70 | /*********************************************************************** 71 | * 该布局采用手动布局 setBounds设置组件位置 * setFont设置字体、字型、字号 * setForeground设置文字的颜色 72 | * * setBackground设置背景色 * setOpaque将背景设置为透明 73 | */ 74 | pnlLogin.setLayout(null); // 组件用手动布局 75 | pnlLogin.setBackground(new Color(52, 130, 203)); 76 | 77 | lblServer.setBounds(50, 100, 100, 30); 78 | txtServer.setBounds(150, 100, 120, 25); 79 | lblUserName.setBounds(50, 130, 100, 30); 80 | txtUserName.setBounds(150, 130, 120, 25); 81 | lblPassword.setBounds(50, 160, 100, 30); 82 | pwdPassword.setBounds(150, 160, 120, 25); 83 | btnLogin.setBounds(50, 200, 80, 25); 84 | btnRegister.setBounds(130, 200, 80, 25); 85 | btnExit.setBounds(210, 200, 80, 25); 86 | 87 | Font fontstr = new Font("宋体", Font.PLAIN, 12); 88 | lblServer.setFont(fontstr); 89 | txtServer.setFont(fontstr); 90 | lblUserName.setFont(fontstr); 91 | txtUserName.setFont(fontstr); 92 | lblPassword.setFont(fontstr); 93 | pwdPassword.setFont(fontstr); 94 | btnLogin.setFont(fontstr); 95 | btnRegister.setFont(fontstr); 96 | btnExit.setFont(fontstr); 97 | 98 | lblUserName.setForeground(Color.BLACK); 99 | lblPassword.setForeground(Color.BLACK); 100 | btnLogin.setBackground(Color.ORANGE); 101 | btnRegister.setBackground(Color.ORANGE); 102 | btnExit.setBackground(Color.ORANGE); 103 | 104 | pnlLogin.add(lblServer); 105 | pnlLogin.add(txtServer); 106 | pnlLogin.add(lblUserName); 107 | pnlLogin.add(txtUserName); 108 | pnlLogin.add(lblPassword); 109 | pnlLogin.add(pwdPassword); 110 | pnlLogin.add(btnLogin); 111 | pnlLogin.add(btnRegister); 112 | pnlLogin.add(btnExit); 113 | 114 | // 设置背景图片 115 | Icon logo1 = new ImageIcon("images\\loginlogo.jpg"); 116 | lblLogo = new JLabel(logo1); 117 | lblLogo.setBounds(0, 0, 340, 66); 118 | pnlLogin.add(lblLogo); 119 | // 设置登录窗口 120 | setResizable(false); 121 | setSize(340, 260); 122 | setVisible(true); 123 | scrnsize = toolkit.getScreenSize(); 124 | setLocation(scrnsize.width / 2 - this.getWidth() / 2, scrnsize.height / 2 - this.getHeight() / 2); 125 | Image img = toolkit.getImage("images\\appico.jpg"); 126 | setIconImage(img); 127 | 128 | // 三个按钮注册监听 129 | btnLogin.addActionListener(this); 130 | btnRegister.addActionListener(this); 131 | btnExit.addActionListener(this); 132 | 133 | } // 构造方法结束 134 | 135 | /** 136 | * 按钮监听响应 137 | */ 138 | @SuppressWarnings({ "deprecation", "static-access" }) 139 | public void actionPerformed(ActionEvent ae) { 140 | Object source = ae.getSource(); 141 | if (source.equals(btnLogin)) { 142 | // 判断用户名和密码是否为空 143 | if (txtUserName.getText().equals("") || pwdPassword.getText().equals("")) { 144 | JOptionPane op1 = new JOptionPane(); 145 | op1.showMessageDialog(null, "用户名或密码不能为空"); 146 | } else { 147 | strServerIp = txtServer.getText(); 148 | login(); 149 | } 150 | } 151 | if (source.equals(btnRegister)) { 152 | strServerIp = txtServer.getText(); 153 | this.dispose(); 154 | new Register(strServerIp); 155 | } 156 | if (source == btnExit) { 157 | System.exit(0); 158 | } 159 | } // actionPerformed()结束 160 | 161 | /** 162 | * 登录事件响应方法 163 | */ 164 | @SuppressWarnings("deprecation") 165 | public void login() { 166 | // 接受客户的详细资料 167 | Customer data = new Customer(); 168 | data.custName = txtUserName.getText(); 169 | data.custPassword = pwdPassword.getText(); 170 | try { 171 | // 连接到服务器 172 | Socket toServer; 173 | toServer = new Socket(strServerIp, 1001); 174 | ObjectOutputStream streamToServer = new ObjectOutputStream(toServer.getOutputStream()); 175 | // 写客户详细资料到服务器socket 176 | streamToServer.writeObject((Customer) data); 177 | // 读来自服务器socket的登录状态 178 | BufferedReader fromServer = new BufferedReader(new InputStreamReader(toServer.getInputStream())); 179 | String status = fromServer.readLine(); 180 | if (status.equals("登录成功")) { 181 | new ChatRoom((String) data.custName, strServerIp); 182 | this.dispose(); 183 | // 关闭流对象 184 | streamToServer.close(); 185 | fromServer.close(); 186 | toServer.close(); 187 | } else { 188 | JOptionPane.showMessageDialog(null, status); 189 | // 关闭流对象 190 | streamToServer.close(); 191 | fromServer.close(); 192 | toServer.close(); 193 | } 194 | } catch (ConnectException e1) { 195 | JOptionPane.showMessageDialog(null, "未能建立到指定服务器的连接!"); 196 | } catch (InvalidClassException e2) { 197 | JOptionPane.showMessageDialog(null, "类错误!"); 198 | } catch (NotSerializableException e3) { 199 | JOptionPane.showMessageDialog(null, "对象未序列化!"); 200 | } catch (IOException e4) { 201 | JOptionPane.showMessageDialog(null, "不能写入到指定服务器!"); 202 | } 203 | } // login()结束 204 | 205 | /** 206 | * 启动登陆窗体 207 | * 208 | * @param args 209 | */ 210 | public static void main(String args[]) { 211 | new Login(); 212 | } 213 | 214 | } // Class Login结束 215 | -------------------------------------------------------------------------------- /src/Register.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | 3 | import java.awt.*; 4 | import java.awt.event.*; 5 | import java.net.*; 6 | import java.io.*; 7 | 8 | /*Title:HappyChat聊天系统用户注册程序
9 | *Description:新用户通过输入相关信息注册成系统用户
10 | *Copyright:Copyright(C)2006
11 | *Filename:Register.java
12 | *@author 刘志成 13 | *@version 1.0 14 | */ 15 | 16 | public class Register extends JFrame implements ActionListener { 17 | private JComboBox comboBox; 18 | /** 19 | * 20 | */ 21 | private static final long serialVersionUID = 9019746127517522180L; 22 | JPanel pnlRegister; 23 | JLabel lblUserName, lblGender, lblAge; 24 | JLabel lblPassword, lblConfirmPass, lblEmail, logoPosition; 25 | JTextField txtUserName, txtAge, txtEmail; 26 | JPasswordField pwdUserPassword, pwdConfirmPass; 27 | JRadioButton rbtnMale, rbtnFemale; 28 | ButtonGroup btngGender; 29 | JButton btnOk, btnCancel, btnClear; 30 | String strServerIp; 31 | final JLabel headLabel = new JLabel(); 32 | // 用于将窗口用于定位 33 | Dimension scrnsize; 34 | Toolkit toolkit = Toolkit.getDefaultToolkit(); 35 | 36 | // 构造方法 37 | public Register(String ip) { 38 | super("[HappyChat]聊天室注册窗口"); 39 | strServerIp = ip; 40 | pnlRegister = new JPanel(); 41 | this.getContentPane().add(pnlRegister); 42 | 43 | lblUserName = new JLabel("用 户 名:"); 44 | lblGender = new JLabel("性 别:"); 45 | lblAge = new JLabel("年 龄:"); 46 | lblPassword = new JLabel("口 令:"); 47 | lblConfirmPass = new JLabel("确认口令:"); 48 | lblEmail = new JLabel("电子邮件:"); 49 | txtUserName = new JTextField(30); 50 | txtEmail = new JTextField(30); 51 | txtAge = new JTextField(10); 52 | pwdUserPassword = new JPasswordField(30); 53 | pwdConfirmPass = new JPasswordField(30); 54 | rbtnMale = new JRadioButton("男", true); 55 | rbtnFemale = new JRadioButton("女"); 56 | btngGender = new ButtonGroup(); 57 | btnOk = new JButton("确定(O)"); 58 | btnOk.setMnemonic('O'); 59 | btnOk.setToolTipText("保存注册信息"); 60 | btnCancel = new JButton("返回(B)"); 61 | btnCancel.setMnemonic('B'); 62 | btnCancel.setToolTipText("返回登录窗口"); 63 | btnClear = new JButton("清空(L)"); 64 | btnClear.setMnemonic('L'); 65 | btnClear.setToolTipText("清空注册信息"); 66 | 67 | /* 68 | * 该布局采用手动布局 * setBounds设置组件位置 * setFont设置字体、字型、字号 * 69 | * setForeground设置文字的颜色 * setBackground设置背景色 * setOpaque将背景设置为透明 70 | */ 71 | pnlRegister.setLayout(null); // 组件用手动布局 72 | pnlRegister.setBackground(new Color(52, 130, 203)); 73 | 74 | lblUserName.setBounds(30, 80, 100, 30); 75 | txtUserName.setBounds(110, 85, 120, 20); 76 | lblPassword.setBounds(30, 141, 100, 30); 77 | pwdUserPassword.setBounds(110, 146, 120, 20); 78 | lblConfirmPass.setBounds(30, 166, 100, 30); 79 | pwdConfirmPass.setBounds(110, 171, 120, 20); 80 | lblGender.setBounds(30, 191, 100, 30); 81 | rbtnMale.setBounds(110, 196, 60, 20); 82 | rbtnFemale.setBounds(190, 196, 60, 20); 83 | lblAge.setBounds(30, 216, 100, 30); 84 | txtAge.setBounds(110, 221, 120, 20); 85 | lblEmail.setBounds(30, 241, 100, 30); 86 | txtEmail.setBounds(110, 246, 120, 20); 87 | 88 | btnOk.setBounds(246, 166, 80, 25); 89 | btnCancel.setBounds(246, 201, 80, 25); 90 | btnClear.setBounds(246, 241, 80, 25); 91 | 92 | Font fontstr = new Font("宋体", Font.PLAIN, 12); 93 | lblUserName.setFont(fontstr); 94 | lblGender.setFont(fontstr); 95 | lblPassword.setFont(fontstr); 96 | lblConfirmPass.setFont(fontstr); 97 | lblAge.setFont(fontstr); 98 | lblEmail.setFont(fontstr); 99 | rbtnMale.setFont(fontstr); 100 | rbtnFemale.setFont(fontstr); 101 | txtUserName.setFont(fontstr); 102 | txtEmail.setFont(fontstr); 103 | btnOk.setFont(fontstr); 104 | btnCancel.setFont(fontstr); 105 | btnClear.setFont(fontstr); 106 | 107 | lblUserName.setForeground(Color.BLACK); 108 | lblGender.setForeground(Color.BLACK); 109 | lblPassword.setForeground(Color.BLACK); 110 | lblAge.setForeground(Color.BLACK); 111 | lblConfirmPass.setForeground(Color.BLACK); 112 | lblEmail.setForeground(Color.BLACK); 113 | rbtnMale.setForeground(Color.BLACK); 114 | rbtnFemale.setForeground(Color.BLACK); 115 | rbtnMale.setBackground(Color.white); 116 | rbtnFemale.setBackground(Color.white); 117 | btnOk.setBackground(Color.ORANGE); 118 | btnCancel.setBackground(Color.ORANGE); 119 | btnClear.setBackground(Color.ORANGE); 120 | rbtnMale.setOpaque(false); 121 | rbtnFemale.setOpaque(false); 122 | 123 | pnlRegister.add(lblUserName); 124 | pnlRegister.add(lblGender); 125 | pnlRegister.add(lblPassword); 126 | pnlRegister.add(lblConfirmPass); 127 | pnlRegister.add(lblEmail); 128 | pnlRegister.add(lblAge); 129 | pnlRegister.add(txtAge); 130 | pnlRegister.add(txtUserName); 131 | pnlRegister.add(txtEmail); 132 | pnlRegister.add(pwdUserPassword); 133 | pnlRegister.add(pwdConfirmPass); 134 | pnlRegister.add(btnOk); 135 | pnlRegister.add(btnCancel); 136 | pnlRegister.add(btnClear); 137 | pnlRegister.add(rbtnMale); 138 | pnlRegister.add(rbtnFemale); 139 | btngGender.add(rbtnMale); 140 | btngGender.add(rbtnFemale); 141 | 142 | // 设置背景图片 143 | Icon logo = new ImageIcon("images\\registerlogo.jpg"); 144 | logoPosition = new JLabel(logo); 145 | logoPosition.setBounds(0, 0, 360, 78); 146 | pnlRegister.add(logoPosition); 147 | 148 | this.setSize(360, 313); 149 | this.setVisible(true); 150 | this.setResizable(false); 151 | // 将窗口定位在屏幕中央 152 | scrnsize = toolkit.getScreenSize(); 153 | this.setLocation(scrnsize.width / 2 - this.getWidth() / 2, scrnsize.height / 2 - this.getHeight() / 2); 154 | Image img = toolkit.getImage("images\\appico.jpg"); 155 | this.setIconImage(img); 156 | // 三个按钮注册监听 157 | btnOk.addActionListener(this); 158 | btnCancel.addActionListener(this); 159 | btnClear.addActionListener(this); 160 | 161 | final JLabel label = new JLabel(); 162 | label.setText("头 像:"); 163 | label.setBounds(30, 120, 60, 15); 164 | pnlRegister.add(label); 165 | 166 | comboBox = new JComboBox(); 167 | comboBox.setAutoscrolls(true); 168 | comboBox.setModel(new DefaultComboBoxModel(new String[] { "1", "2", "3" })); 169 | comboBox.setBounds(110, 116, 47, 23); 170 | comboBox.addItemListener(new ItemListener() { 171 | 172 | public void itemStateChanged(ItemEvent arg0) { 173 | Icon logo = new ImageIcon("face\\" + comboBox.getSelectedItem().toString() + ".jpg"); 174 | // TODO 自动生成方法存根 175 | headLabel.setIcon(logo); 176 | } 177 | }); 178 | pnlRegister.add(comboBox); 179 | 180 | headLabel.setHorizontalAlignment(SwingConstants.CENTER); 181 | // .setIcon(SwingResourceManager.getIcon(Register.class, "face/1.jpg")); 182 | headLabel.setIcon(new ImageIcon("face//1.JPG")); 183 | headLabel.setBounds(247, 88, 74, 72); 184 | pnlRegister.add(headLabel); 185 | } // 构造方法结束 186 | 187 | // 按钮监听响应 188 | public void actionPerformed(ActionEvent ae) { 189 | Object source = new Object(); 190 | source = ae.getSource(); 191 | if (source.equals(btnOk)) // "确定"按钮 192 | { 193 | register(); 194 | } 195 | if (source.equals(btnCancel)) // "返回"按钮 196 | { 197 | new Login(); 198 | this.dispose(); 199 | } 200 | if (source.equals(btnClear)) // "清空"按钮 201 | { 202 | txtUserName.setText(""); 203 | pwdUserPassword.setText(""); 204 | pwdConfirmPass.setText(""); 205 | txtAge.setText(""); 206 | txtEmail.setText(""); 207 | } 208 | } // actionPerformed()结束 209 | 210 | ////////// "确定"按钮事件响应////////// 211 | @SuppressWarnings({ "deprecation", "static-access" }) 212 | public void register() { 213 | // 接受客户的详细资料 214 | Register_Customer data = new Register_Customer(); 215 | data.custName = txtUserName.getText(); 216 | data.custPassword = pwdUserPassword.getText(); 217 | data.age = txtAge.getText(); 218 | data.sex = rbtnMale.isSelected() ? "男" : "女"; 219 | data.email = txtEmail.getText(); 220 | // chenmin 221 | data.head = comboBox.getSelectedItem().toString(); 222 | // 验证用户名是否为空 223 | if (data.custName.length() == 0) { 224 | JOptionPane.showMessageDialog(null, "用户名不能为空"); 225 | return; 226 | } 227 | // 验证密码是否为空 228 | if (data.custPassword.length() == 0) { 229 | JOptionPane.showMessageDialog(null, "密码不能为空"); 230 | return; 231 | } 232 | 233 | // 验证密码的一致性 234 | if (!data.custPassword.equals(pwdConfirmPass.getText())) { 235 | JOptionPane.showMessageDialog(null, "密码两次输入不一致,请重新输入"); 236 | return; 237 | } 238 | 239 | // 验证年龄是否为空 240 | if (data.age.length() == 0) { 241 | JOptionPane.showMessageDialog(null, "年龄不能为空"); 242 | return; 243 | } 244 | // 验证年龄的合法性 245 | int age = Integer.parseInt(txtAge.getText()); 246 | if (age <= 0 || age > 100) { 247 | JOptionPane.showMessageDialog(null, "年龄输入不合法"); 248 | return; 249 | } 250 | // 验证Email的正确性 251 | int Found_flag = 0; // 判断标志 252 | for (int i = 0; i < data.email.length(); i++) { 253 | if (data.email.charAt(i) == '@') { 254 | Found_flag++; 255 | } 256 | } 257 | if (Found_flag != 1) { 258 | JOptionPane.showMessageDialog(null, "电子邮箱格式不正确,请重新输入"); 259 | return; 260 | } 261 | 262 | try { 263 | // 连接到服务器 264 | Socket toServer; 265 | toServer = new Socket(strServerIp, 1001); 266 | ObjectOutputStream streamToServer = new ObjectOutputStream(toServer.getOutputStream()); 267 | // 写客户详细资料到服务器socket 268 | streamToServer.writeObject((Register_Customer) data); 269 | // 读来自服务器socket的登陆状态 270 | BufferedReader fromServer = new BufferedReader(new InputStreamReader(toServer.getInputStream())); 271 | String status = fromServer.readLine(); 272 | // 显示成功消息 273 | JOptionPane op = new JOptionPane(); 274 | op.showMessageDialog(null, status); 275 | if (status.equals(data.custName + "注册成功")) { 276 | txtUserName.setText(""); 277 | pwdUserPassword.setText(""); 278 | pwdConfirmPass.setText(""); 279 | txtAge.setText(""); 280 | txtEmail.setText(""); 281 | } 282 | 283 | // 关闭流对象 284 | streamToServer.close(); 285 | fromServer.close(); 286 | } catch (InvalidClassException e1) { 287 | JOptionPane.showMessageDialog(null, "类错误!"); 288 | } catch (NotSerializableException e2) { 289 | JOptionPane.showMessageDialog(null, "对象未序列化!"); 290 | } catch (IOException e3) { 291 | JOptionPane.showMessageDialog(null, "不能写入到指定服务器!"); 292 | } 293 | 294 | } // 方法register()结束 295 | 296 | public static void main(String args[]) { 297 | new Register("127.0.0.1"); 298 | } 299 | 300 | } // class Register 结束 301 | -------------------------------------------------------------------------------- /src/ServerFrame.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.awt.event.ActionEvent; 3 | import java.awt.event.ActionListener; 4 | import java.io.FileOutputStream; 5 | 6 | import javax.swing.*; 7 | 8 | //////////*服务器窗口类*/////////////// 9 | public class ServerFrame extends JFrame implements ActionListener { 10 | public JList list; 11 | /** 12 | * 13 | */ 14 | private static final long serialVersionUID = -8936397327038098620L; 15 | 16 | // 服务器信息面板 17 | JPanel pnlServer, pnlServerInfo; 18 | 19 | JLabel lblStatus, lblNumber, lblMax, lblServerName, lblProtocol, lblIP, lblPort, lblLog; 20 | 21 | public JTextField txtStatus, txtNumber, txtMax, txtServerName, txtProtocol, txtIP, txtPort; 22 | 23 | JButton btnStop, btnSaveLog; 24 | 25 | public TextArea taLog; 26 | 27 | JTabbedPane tpServer; 28 | 29 | public TextArea taMessage; 30 | 31 | // 用户信息面板 32 | JPanel pnlUser; 33 | 34 | public JLabel lblMessage, lblUser, lblNotice, lblUserCount; 35 | 36 | JList lstUser; 37 | 38 | JScrollPane spUser; 39 | 40 | JTextField txtNotice; 41 | 42 | JButton btnSend, btnKick; 43 | 44 | public String ti = ""; 45 | 46 | public String serverMessage = ""; 47 | 48 | public ServerFrame() { 49 | // 服务器窗口 50 | super("[HappyChat]聊天服务器"); 51 | setSize(550, 500); 52 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 53 | setResizable(false); 54 | Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();// 在屏幕居中显示 55 | Dimension fra = this.getSize(); 56 | if (fra.width > scr.width) { 57 | fra.width = scr.width; 58 | } 59 | if (fra.height > scr.height) { 60 | fra.height = scr.height; 61 | } 62 | this.setLocation((scr.width - fra.width) / 2, (scr.height - fra.height) / 2); 63 | 64 | // ==========服务器信息面板========================= 65 | pnlServer = new JPanel(); 66 | pnlServer.setLayout(null); 67 | pnlServer.setBackground(new Color(52, 130, 203)); 68 | 69 | pnlServerInfo = new JPanel(new GridLayout(14, 1)); 70 | pnlServerInfo.setBackground(new Color(52, 130, 203)); 71 | pnlServerInfo.setFont(new Font("宋体", 0, 12)); 72 | pnlServerInfo.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(""), 73 | BorderFactory.createEmptyBorder(1, 1, 1, 1))); 74 | 75 | lblStatus = new JLabel("当前状态:"); 76 | lblStatus.setForeground(Color.YELLOW); 77 | lblStatus.setFont(new Font("宋体", 0, 12)); 78 | txtStatus = new JTextField(10); 79 | txtStatus.setBackground(Color.decode("#d6f4f2")); 80 | txtStatus.setFont(new Font("宋体", 0, 12)); 81 | txtStatus.setEditable(false); 82 | 83 | lblNumber = new JLabel("当前在线人数:"); 84 | lblNumber.setForeground(Color.YELLOW); 85 | lblNumber.setFont(new Font("宋体", 0, 12)); 86 | txtNumber = new JTextField("0 人", 10); 87 | txtNumber.setBackground(Color.decode("#d6f4f2")); 88 | txtNumber.setFont(new Font("宋体", 0, 12)); 89 | txtNumber.setEditable(false); 90 | 91 | lblMax = new JLabel("最多在线人数:"); 92 | lblMax.setForeground(Color.YELLOW); 93 | lblMax.setFont(new Font("宋体", 0, 12)); 94 | txtMax = new JTextField("50 人", 10); 95 | txtMax.setBackground(Color.decode("#d6f4f2")); 96 | txtMax.setFont(new Font("宋体", 0, 12)); 97 | txtMax.setEditable(false); 98 | 99 | lblServerName = new JLabel("服务器名称:"); 100 | lblServerName.setForeground(Color.YELLOW); 101 | lblServerName.setFont(new Font("宋体", 0, 12)); 102 | txtServerName = new JTextField(10); 103 | txtServerName.setBackground(Color.decode("#d6f4f2")); 104 | txtServerName.setFont(new Font("宋体", 0, 12)); 105 | txtServerName.setEditable(false); 106 | 107 | lblProtocol = new JLabel("访问协议:"); 108 | lblProtocol.setForeground(Color.YELLOW); 109 | lblProtocol.setFont(new Font("宋体", 0, 12)); 110 | txtProtocol = new JTextField("HTTP", 10); 111 | txtProtocol.setBackground(Color.decode("#d6f4f2")); 112 | txtProtocol.setFont(new Font("宋体", 0, 12)); 113 | txtProtocol.setEditable(false); 114 | 115 | lblIP = new JLabel("服务器IP:"); 116 | lblIP.setForeground(Color.YELLOW); 117 | lblIP.setFont(new Font("宋体", 0, 12)); 118 | txtIP = new JTextField(10); 119 | txtIP.setBackground(Color.decode("#d6f4f2")); 120 | txtIP.setFont(new Font("宋体", 0, 12)); 121 | txtIP.setEditable(false); 122 | 123 | lblPort = new JLabel("服务器端口:"); 124 | lblPort.setForeground(Color.YELLOW); 125 | lblPort.setFont(new Font("宋体", 0, 12)); 126 | txtPort = new JTextField("8000", 10); 127 | txtPort.setBackground(Color.decode("#d6f4f2")); 128 | txtPort.setFont(new Font("宋体", 0, 12)); 129 | txtPort.setEditable(false); 130 | 131 | btnStop = new JButton("关闭服务器(C)"); 132 | btnStop.addActionListener(new ActionListener() { 133 | public void actionPerformed(ActionEvent arg0) { 134 | closeServer(); 135 | } 136 | }); 137 | btnStop.setBackground(Color.ORANGE); 138 | btnStop.setFont(new Font("宋体", 0, 12)); 139 | 140 | lblLog = new JLabel("[服务器日志]"); 141 | lblLog.setForeground(Color.YELLOW); 142 | lblLog.setFont(new Font("宋体", 0, 12)); 143 | 144 | taLog = new TextArea(20, 50); 145 | taLog.setFont(new Font("宋体", 0, 12)); 146 | btnSaveLog = new JButton("保存日志(S)"); 147 | btnSaveLog.addActionListener(new ActionListener() { 148 | public void actionPerformed(ActionEvent arg0) { 149 | saveLog(); 150 | } 151 | }); 152 | btnSaveLog.setBackground(Color.ORANGE); 153 | btnSaveLog.setFont(new Font("宋体", 0, 12)); 154 | 155 | pnlServerInfo.add(lblStatus); 156 | pnlServerInfo.add(txtStatus); 157 | pnlServerInfo.add(lblNumber); 158 | pnlServerInfo.add(txtNumber); 159 | pnlServerInfo.add(lblMax); 160 | pnlServerInfo.add(txtMax); 161 | pnlServerInfo.add(lblServerName); 162 | pnlServerInfo.add(txtServerName); 163 | pnlServerInfo.add(lblProtocol); 164 | pnlServerInfo.add(txtProtocol); 165 | pnlServerInfo.add(lblIP); 166 | pnlServerInfo.add(txtIP); 167 | pnlServerInfo.add(lblPort); 168 | pnlServerInfo.add(txtPort); 169 | 170 | pnlServerInfo.setBounds(5, 5, 100, 400); 171 | lblLog.setBounds(110, 5, 100, 30); 172 | taLog.setBounds(110, 35, 400, 370); 173 | btnStop.setBounds(200, 410, 120, 30); 174 | btnSaveLog.setBounds(320, 410, 120, 30); 175 | pnlServer.add(pnlServerInfo); 176 | pnlServer.add(lblLog); 177 | pnlServer.add(taLog); 178 | pnlServer.add(btnStop); 179 | pnlServer.add(btnSaveLog); 180 | // ===========在线用户面板==================== 181 | pnlUser = new JPanel(); 182 | pnlUser.setLayout(null); 183 | pnlUser.setBackground(new Color(52, 130, 203)); 184 | pnlUser.setFont(new Font("宋体", 0, 12)); 185 | lblMessage = new JLabel("[用户消息]"); 186 | lblMessage.setFont(new Font("宋体", 0, 12)); 187 | lblMessage.setForeground(Color.YELLOW); 188 | taMessage = new TextArea(20, 20); 189 | taMessage.setFont(new Font("宋体", 0, 12)); 190 | lblNotice = new JLabel("通知:"); 191 | lblNotice.setFont(new Font("宋体", 0, 12)); 192 | txtNotice = new JTextField(20); 193 | txtNotice.setFont(new Font("宋体", 0, 12)); 194 | btnSend = new JButton("发送(S)"); 195 | btnSend.setBackground(Color.ORANGE); 196 | btnSend.setFont(new Font("宋体", 0, 12)); 197 | btnSend.setEnabled(true); 198 | btnSend.addActionListener(new ActionListener() { 199 | public void actionPerformed(ActionEvent arg0) { 200 | serverMessage(); 201 | } 202 | }); 203 | 204 | lblUserCount = new JLabel("在线总人数 0 人"); 205 | lblUserCount.setFont(new Font("宋体", 0, 12)); 206 | 207 | btnKick = new JButton("踢人(K)"); 208 | btnKick.addActionListener(new ActionListener() { 209 | public void actionPerformed(ActionEvent arg0) { 210 | tiRen(); 211 | } 212 | }); 213 | btnKick.setBackground(Color.ORANGE); 214 | btnKick.setFont(new Font("宋体", 0, 12)); 215 | lblUser = new JLabel("[在线用户列表]"); 216 | lblUser.setFont(new Font("宋体", 0, 12)); 217 | lblUser.setForeground(Color.YELLOW); 218 | 219 | lstUser = new JList(); 220 | lstUser.setFont(new Font("宋体", 0, 12)); 221 | lstUser.setVisibleRowCount(17); 222 | lstUser.setFixedCellWidth(180); 223 | lstUser.setFixedCellHeight(18); 224 | // lstUser.setListData(listVector); 225 | 226 | spUser = new JScrollPane(); 227 | spUser.setBackground(Color.decode("#d6f4f2")); 228 | spUser.setFont(new Font("宋体", 0, 12)); 229 | // spUser.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 230 | spUser.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 231 | spUser.getViewport().setView(lstUser); 232 | 233 | lblMessage.setBounds(5, 5, 100, 25); 234 | taMessage.setBounds(5, 35, 300, 360); 235 | lblUser.setBounds(310, 5, 100, 25); 236 | spUser.setBounds(310, 35, 220, 360); 237 | lblNotice.setBounds(5, 410, 40, 25); 238 | txtNotice.setBounds(50, 410, 160, 25); 239 | btnSend.setBounds(210, 410, 80, 25); 240 | lblUserCount.setBounds(320, 410, 100, 25); 241 | btnKick.setBounds(440, 410, 80, 25); 242 | 243 | pnlUser.add(lblMessage); 244 | pnlUser.add(taMessage); 245 | pnlUser.add(lblUser); 246 | pnlUser.add(spUser); 247 | 248 | list = new JList(); 249 | list.setListData(new String[] { "" }); 250 | // list.setModel(null); 251 | // .setListData(null); 252 | spUser.setViewportView(list); 253 | // list.setListData(null); 254 | pnlUser.add(lblNotice); 255 | pnlUser.add(txtNotice); 256 | pnlUser.add(btnSend); 257 | pnlUser.add(lblUserCount); 258 | pnlUser.add(btnKick); 259 | 260 | // ============主标签面板======================== 261 | 262 | tpServer = new JTabbedPane(JTabbedPane.TOP); 263 | tpServer.setBackground(Color.decode("#d6f4f2")); 264 | tpServer.setFont(new Font("宋体", 0, 12)); 265 | tpServer.add("服务器管理", pnlServer); 266 | tpServer.add("用户信息管理", pnlUser); 267 | this.getContentPane().add(tpServer); 268 | setVisible(true); 269 | } 270 | 271 | protected void serverMessage() { 272 | // TODO 自动生成方法存根 273 | this.serverMessage = txtNotice.getText(); 274 | txtNotice.setText(""); 275 | } 276 | 277 | protected void closeServer() { 278 | // TODO 自动生成方法存根 279 | this.dispose(); 280 | // this.res 281 | } 282 | 283 | protected void saveLog() { 284 | // TODO 自动生成方法存根 285 | try { 286 | FileOutputStream fileoutput = new FileOutputStream("log.txt", true); 287 | String temp = taMessage.getText(); 288 | // System.out.println(temp); 289 | fileoutput.write(temp.getBytes()); 290 | fileoutput.close(); 291 | JOptionPane.showMessageDialog(null, "记录保存在log.txt"); 292 | } catch (Exception e) { 293 | System.out.println(e); 294 | } 295 | } 296 | 297 | protected void tiRen() { 298 | // TODO 自动生成方法存根 299 | // System.out.println("Ti:"+list.getSelectedValue().toString()); 300 | ti = list.getSelectedValue().toString(); 301 | log("Ti:" + ti); 302 | } 303 | 304 | private void log(String string) { 305 | // TODO 自动生成方法存根 306 | String newta = taMessage.getText(); 307 | newta += ("\n" + string); 308 | taMessage.setText(newta); 309 | } 310 | 311 | public void actionPerformed(ActionEvent evt) { 312 | 313 | } 314 | 315 | public static void main(String args[]) { 316 | new ServerFrame(); 317 | } 318 | } -------------------------------------------------------------------------------- /src/Connection.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.FileInputStream; 3 | import java.io.FileOutputStream; 4 | import java.io.IOException; 5 | import java.io.ObjectInputStream; 6 | import java.io.ObjectOutputStream; 7 | import java.io.PrintStream; 8 | import java.net.Socket; 9 | import java.util.Date; 10 | import java.util.Vector; 11 | 12 | /** 13 | *14 | * Title: HappyChat聊天系统服务器程序 15 | *
16 | *17 | * Description: 聊天服务器 18 | *
19 | *20 | * Copyright: Copyright (c) 2006 21 | *
22 | *23 | * Filename: Connection.java 24 | *
25 | * 26 | * 27 | * 28 | * 封装注册信息Title:HappyChat聊天系统聊天程序
12 | *Description:系统用户登录后进行聊天
13 | *Copyright:Copyright (C)2006
14 | *Filename:ChatRoom.java
15 | *@author 刘志 16 | *@version 1.0 17 | */ 18 | 19 | public class ChatRoom extends Thread implements ActionListener { 20 | private JComboBox daXiaoComboBox; 21 | 22 | private JComboBox yangShiComboBox; 23 | 24 | private JComboBox zitiComboBox; 25 | 26 | private JComboBox emote; 27 | 28 | static JFrame frmChat; 29 | 30 | JPanel pnlChat; 31 | 32 | JButton btnCls, btnExit, btnSend, btnClear, btnSave, btnTimer; 33 | 34 | JLabel lblUserList, lblUserMessage, lblSendMessage, lblChatUser; 35 | 36 | JLabel lblUserTotal, lblCount, lblBack; 37 | 38 | JTextField txtMessage; 39 | 40 | java.awt.List lstUserList; 41 | 42 | TextArea taUserMessage; 43 | 44 | JComboBox cmbUser; 45 | 46 | JCheckBox chPrivateChat; 47 | 48 | String strServerIp, strLoginName; 49 | 50 | Thread thread; 51 | 52 | final JLabel headLabel = new JLabel(); 53 | 54 | // 用于将窗口用于定位 55 | Dimension scrnsize; 56 | 57 | Toolkit toolkit = Toolkit.getDefaultToolkit(); 58 | 59 | Message messobj = null; 60 | 61 | String serverMessage = ""; 62 | 63 | final JSlider blueSlider = new JSlider(); 64 | 65 | final JSlider redSlider = new JSlider(); 66 | 67 | final JSlider greenSlider = new JSlider(); 68 | 69 | final JLabel hanziLabel = new JLabel(); 70 | 71 | // 构造方法 72 | public ChatRoom(String name, String ip) { 73 | // Dialog d = new FontDialog(); 74 | strServerIp = ip; 75 | strLoginName = name; 76 | frmChat = new JFrame("聊天室" + "[用户:" + name + "]"); 77 | pnlChat = new JPanel(); 78 | frmChat.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 79 | frmChat.getContentPane().add(pnlChat); 80 | 81 | Font fntDisp1 = new Font("宋体", Font.PLAIN, 12); 82 | 83 | String list[] = { "所有人" }; 84 | btnCls = new JButton("清屏(C)"); 85 | btnExit = new JButton("退出(X)"); 86 | btnSend = new JButton("发送(N)"); 87 | btnSave = new JButton("保存(S)"); 88 | btnTimer = new JButton("时钟(T)"); 89 | lblUserList = new JLabel("【在线用户列表】"); 90 | lblUserMessage = new JLabel("【聊天信息】"); 91 | lblSendMessage = new JLabel("聊天内容:"); 92 | lblChatUser = new JLabel("你对:"); 93 | lblUserTotal = new JLabel("在线人数:"); 94 | lblCount = new JLabel("0"); 95 | lstUserList = new java.awt.List(); 96 | txtMessage = new JTextField(170); 97 | cmbUser = new JComboBox(list); 98 | // chenmin 99 | cmbUser.addItemListener(new ItemListener() { 100 | public void itemStateChanged(ItemEvent arg0) { 101 | freshHead(); 102 | } 103 | }); 104 | chPrivateChat = new JCheckBox("私聊"); 105 | taUserMessage = new TextArea("", 300, 200, TextArea.SCROLLBARS_VERTICAL_ONLY);// 只能向下滚动 106 | // taUserMessage.setText("aaaaaa汉字aaaa"); 107 | taUserMessage.setForeground(new Color(0, 0, 0)); 108 | taUserMessage.setEditable(false); // 不可写入 109 | 110 | /*********************************************************************** 111 | * 该布局采用手动布局 setBounds设置组件位置 * setFont设置字体、字型、字号 * setForeground设置文字的颜色 112 | * * setBackground设置背景色 * setOpaque将背景设置为透明 113 | */ 114 | 115 | pnlChat.setLayout(null); 116 | pnlChat.setBackground(new Color(52, 130, 203)); 117 | btnTimer.setBounds(400, 360, 80, 25); 118 | btnSave.setBounds(500, 330, 80, 25); 119 | btnCls.setBounds(400, 330, 80, 25); 120 | btnExit.setBounds(500, 360, 80, 25); 121 | btnSend.setBounds(500, 300, 80, 25); 122 | 123 | lblUserList.setBounds(5, 0, 120, 40); 124 | lblUserTotal.setBounds(130, 0, 60, 40); 125 | lblCount.setBounds(190, 0, 60, 40); 126 | lblUserMessage.setBounds(225, 0, 180, 40); 127 | lblChatUser.setBounds(10, 290, 40, 40); 128 | lblSendMessage.setBounds(210, 290, 60, 40); 129 | 130 | // lblUserTotal.setBounds(10,340,100,40); 131 | // lblCount.setBounds(73,340,100,40); 132 | lstUserList.setBounds(5, 40, 210, 255); 133 | taUserMessage.setBounds(225, 40, 360, 255); 134 | txtMessage.setBounds(270, 300, 210, 25); 135 | cmbUser.setBounds(50, 300, 80, 25); 136 | chPrivateChat.setBounds(333, 336, 60, 20); 137 | btnTimer.setFont(fntDisp1); 138 | btnCls.setFont(fntDisp1); 139 | btnExit.setFont(fntDisp1); 140 | btnSend.setFont(fntDisp1); 141 | btnSave.setFont(fntDisp1); 142 | lblUserList.setFont(fntDisp1); 143 | lblUserMessage.setFont(fntDisp1); 144 | lblChatUser.setFont(fntDisp1); 145 | lblSendMessage.setFont(fntDisp1); 146 | lblUserTotal.setFont(fntDisp1); 147 | lblCount.setFont(fntDisp1); 148 | cmbUser.setFont(fntDisp1); 149 | chPrivateChat.setFont(fntDisp1); 150 | // taUserMessage.setFont(new Font("新宋体", Font.BOLD | Font.ITALIC, 20)); 151 | 152 | lblUserList.setForeground(Color.YELLOW); 153 | lblUserMessage.setForeground(Color.YELLOW); 154 | lblSendMessage.setForeground(Color.black); 155 | lblChatUser.setForeground(Color.black); 156 | lblSendMessage.setForeground(Color.black); 157 | lblUserTotal.setForeground(Color.YELLOW); 158 | lblCount.setForeground(Color.YELLOW); 159 | cmbUser.setForeground(Color.black); 160 | chPrivateChat.setForeground(Color.black); 161 | lstUserList.setBackground(Color.white); 162 | taUserMessage.setBackground(Color.white); 163 | btnTimer.setBackground(Color.ORANGE); 164 | btnCls.setBackground(Color.ORANGE); 165 | btnExit.setBackground(Color.ORANGE); 166 | btnSend.setBackground(Color.PINK); 167 | btnSave.setBackground(Color.ORANGE); 168 | pnlChat.add(btnTimer); 169 | pnlChat.add(btnCls); 170 | pnlChat.add(btnExit); 171 | pnlChat.add(btnSend); 172 | pnlChat.add(btnSave); 173 | pnlChat.add(lblUserList); 174 | pnlChat.add(lblUserMessage); 175 | pnlChat.add(lblSendMessage); 176 | pnlChat.add(lblChatUser); 177 | pnlChat.add(lblUserTotal); 178 | pnlChat.add(lblCount); 179 | pnlChat.add(lstUserList); 180 | pnlChat.add(taUserMessage); 181 | pnlChat.add(txtMessage); 182 | pnlChat.add(cmbUser); 183 | pnlChat.add(chPrivateChat); 184 | 185 | frmChat.addWindowListener(new Windowclose()); 186 | btnTimer.addActionListener(this); 187 | btnCls.addActionListener(this); 188 | btnExit.addActionListener(this); 189 | btnSend.addActionListener(this); 190 | btnSave.addActionListener(this); 191 | lstUserList.addActionListener(this); 192 | txtMessage.addActionListener(this); 193 | 194 | headLabel.setHorizontalAlignment(SwingConstants.CENTER); 195 | headLabel.setIcon(new ImageIcon("face//1.JPG")); 196 | headLabel.setBounds(15, 335, 70, 60); 197 | pnlChat.add(headLabel); 198 | 199 | emote = new JComboBox(); 200 | emote.setModel(new DefaultComboBoxModel(new String[] { "表情", "微笑", "甜笑", "惊喜", "嘻嘻", "扮酷", "嘿嘿", "傻笑", "好奇", 201 | "媚眼", "鬼脸", "陶醉", "害羞", "生气", "嚷嚷", "发怒", "伤心", "高明", "菜鸟", "问号", "狂笑", "大哭", "示爱", "呻吟", "想想" })); 202 | emote.setBounds(141, 301, 60, 23); 203 | pnlChat.add(emote); 204 | 205 | zitiComboBox = new JComboBox(); 206 | zitiComboBox.addItemListener(new ItemListener() { 207 | public void itemStateChanged(ItemEvent arg0) { 208 | freshFont(); 209 | } 210 | 211 | }); 212 | zitiComboBox.setModel(new DefaultComboBoxModel(new String[] { "宋体", "黑体" })); 213 | zitiComboBox.setBounds(76, 337, 64, 23); 214 | pnlChat.add(zitiComboBox); 215 | 216 | yangShiComboBox = new JComboBox(); 217 | yangShiComboBox.setModel(new DefaultComboBoxModel(new String[] { "正规", "粗体", "斜体", "粗斜" })); 218 | yangShiComboBox.setBounds(153, 337, 52, 23); 219 | yangShiComboBox.addItemListener(new ItemListener() { 220 | public void itemStateChanged(ItemEvent arg0) { 221 | freshFont(); 222 | } 223 | 224 | }); 225 | pnlChat.add(yangShiComboBox); 226 | 227 | daXiaoComboBox = new JComboBox(); 228 | daXiaoComboBox.setModel(new DefaultComboBoxModel(new String[] { "12", "14", "16", "18", "20" })); 229 | daXiaoComboBox.addItemListener(new ItemListener() { 230 | public void itemStateChanged(ItemEvent arg0) { 231 | freshFont(); 232 | } 233 | 234 | }); 235 | daXiaoComboBox.setBounds(220, 335, 40, 23); 236 | pnlChat.add(daXiaoComboBox); 237 | 238 | blueSlider.setMaximum(255); 239 | blueSlider.setValue(128); 240 | blueSlider.setMinimum(0); 241 | blueSlider.addChangeListener(new ChangeListener() { 242 | 243 | public void stateChanged(ChangeEvent arg0) { 244 | // TODO 自动生成方法存根 245 | freshColor(); 246 | } 247 | }); 248 | // slider.setModel(null); 249 | blueSlider.setBounds(80, 365, 180, 10); 250 | pnlChat.add(blueSlider); 251 | 252 | redSlider.setMaximum(255); 253 | redSlider.setValue(128); 254 | redSlider.setMinimum(0); 255 | redSlider.addChangeListener(new ChangeListener() { 256 | 257 | public void stateChanged(ChangeEvent arg0) { 258 | // TODO 自动生成方法存根 259 | freshColor(); 260 | } 261 | }); 262 | redSlider.setBounds(80, 380, 180, 10); 263 | pnlChat.add(redSlider); 264 | 265 | greenSlider.setMaximum(255); 266 | greenSlider.setValue(128); 267 | greenSlider.setMinimum(0); 268 | greenSlider.addChangeListener(new ChangeListener() { 269 | 270 | public void stateChanged(ChangeEvent arg0) { 271 | // TODO 自动生成方法存根 272 | freshColor(); 273 | } 274 | }); 275 | greenSlider.setBounds(80, 395, 180, 10); 276 | pnlChat.add(greenSlider); 277 | 278 | hanziLabel.setForeground(new Color(128, 128, 128)); 279 | hanziLabel.setHorizontalAlignment(SwingConstants.CENTER); 280 | hanziLabel.setFont(new Font("宋体", Font.BOLD, 18)); 281 | hanziLabel.setBackground(Color.ORANGE); 282 | hanziLabel.setText("汉字"); 283 | hanziLabel.setBounds(273, 360, 57, 50); 284 | pnlChat.add(hanziLabel); 285 | 286 | // 启动聊天页面信息刷新线程 287 | Thread thread = new Thread(this); 288 | thread.start(); 289 | 290 | // Icon log=new ImageIcon("images\\chat.jpg"); 291 | // lblBack = new JLabel(log); 292 | // lblBack.setBounds(1, 1, 600,420); 293 | // pnlChat.add(lblBack); 294 | 295 | frmChat.setSize(600, 461); 296 | frmChat.setVisible(true); 297 | frmChat.setResizable(false); 298 | 299 | // 将窗口定位在屏幕中央 300 | scrnsize = toolkit.getScreenSize(); 301 | frmChat.setLocation(scrnsize.width / 2 - frmChat.getWidth() / 2, scrnsize.height / 2 - frmChat.getHeight() / 2); 302 | Image img = toolkit.getImage("images\\appico.jpg"); 303 | frmChat.setIconImage(img); 304 | 305 | } // 构造方法结束 306 | 307 | protected void freshFont() { 308 | // TODO 自动生成方法存根 309 | String ziti = zitiComboBox.getSelectedItem().toString(); 310 | int yangShi = 0; 311 | String yangShiString = yangShiComboBox.getSelectedItem().toString(); 312 | if (yangShiString.equals("常规")) { 313 | yangShi = Font.PLAIN; 314 | } else if (yangShiString.equals("粗体")) { 315 | yangShi = Font.BOLD; 316 | } else if (yangShiString.equals("斜体")) { 317 | yangShi = Font.ITALIC; 318 | } else if (yangShiString.equals("粗斜")) { 319 | yangShi = Font.BOLD | Font.ITALIC; 320 | } 321 | 322 | int daXiao = Integer.parseInt(daXiaoComboBox.getSelectedItem().toString()); 323 | taUserMessage.setFont(new Font(ziti, yangShi, daXiao)); 324 | taUserMessage.setForeground(hanziLabel.getForeground()); 325 | } 326 | 327 | protected void freshColor() { 328 | // TODO 自动生成方法存根 329 | hanziLabel.setForeground(new Color(blueSlider.getValue(), redSlider.getValue(), greenSlider.getValue())); 330 | freshFont(); 331 | } 332 | 333 | @SuppressWarnings("deprecation") 334 | public void run() { 335 | int intMessageCounter = 0; 336 | int intUserTotal = 0; 337 | boolean isFirstLogin = true; // 判断是否刚登陆 338 | boolean isFound; // 判断是否找到用户 339 | Vector user_exit = new Vector(); 340 | 341 | try { 342 | // Socket toServer; 343 | // toServer = new Socket(strServerIp, 1001); 344 | for (;;) { 345 | Socket toServer; 346 | toServer = new Socket(strServerIp, 1001); 347 | // 将信息发往服务器 348 | messobj = new Message(); 349 | ObjectOutputStream streamtoserver = new ObjectOutputStream(toServer.getOutputStream()); 350 | streamtoserver.writeObject((Message) messobj); 351 | // 收来自服务器的信息 352 | ObjectInputStream streamfromserver = new ObjectInputStream(toServer.getInputStream()); 353 | messobj = (Message) streamfromserver.readObject(); 354 | // //////刷新聊天信息列表////////// 355 | if (isFirstLogin) // 如果刚登陆 356 | { 357 | intMessageCounter = messobj.chat.size(); // 屏蔽该用户登陆前的聊天内容 358 | isFirstLogin = false; 359 | } 360 | if (strLoginName.equals(messobj.ti)) { 361 | // taUserMessage.append("ni bei ti"); 362 | exitChatRoom(); 363 | JOptionPane.showMessageDialog(null, strLoginName + "你被管理员剔除!"); 364 | 365 | } 366 | 367 | if (!serverMessage.equals(messobj.serverMessage)) { 368 | serverMessage = messobj.serverMessage; 369 | taUserMessage.append("[系统消息]:" + serverMessage + "\n"); 370 | } 371 | // taUserMessage.setText(""); 372 | for (int i = intMessageCounter; i < messobj.chat.size(); i++) { 373 | Chat temp = (Chat) messobj.chat.elementAt(i); 374 | // chenmin 375 | 376 | String emote = temp.emote; 377 | if (emote.equals("表情")) { 378 | emote = ""; 379 | } else { 380 | emote += "地"; 381 | } 382 | String temp_message; 383 | if (temp.chatUser.equals(strLoginName)) { 384 | if (temp.chatToUser.equals(strLoginName)) { 385 | temp_message = "系统提示您:请不要自言自语!" + "\n"; 386 | } else { 387 | if (!temp.whisper) // 不是悄悄话 388 | { 389 | temp_message = "【你】对【" + temp.chatToUser + "】" + emote + "说:" + temp.chatMessage + "\n"; 390 | } else { 391 | temp_message = "【你】悄悄对【" + temp.chatToUser + "】" + emote + "说:" + temp.chatMessage 392 | + "\n"; 393 | } 394 | } 395 | } else { 396 | if (temp.chatToUser.equals(strLoginName)) { 397 | if (!temp.whisper) // 不是悄悄话 398 | { 399 | temp_message = "【" + temp.chatUser + "】对【你】" + emote + "说:" + temp.chatMessage + "\n"; 400 | } else { 401 | temp_message = "【" + temp.chatUser + "】悄悄对【你】" + emote + "说:" + temp.chatMessage + "\n"; 402 | } 403 | } else { 404 | if (!temp.chatUser.equals(temp.chatToUser)) // 对方没有自言自语 405 | { 406 | if (!temp.whisper) // 不是悄悄话 407 | { 408 | temp_message = "【" + temp.chatUser + "】对【" + temp.chatToUser + "】" + emote + "说:" 409 | + temp.chatMessage + "\n"; 410 | } else { 411 | temp_message = ""; 412 | } 413 | } else { 414 | temp_message = ""; 415 | } 416 | } 417 | } 418 | taUserMessage.append(temp_message); 419 | intMessageCounter++; 420 | } 421 | 422 | // //////刷新在线用户////////// 423 | lstUserList.clear(); 424 | for (int i = 0; i < messobj.userOnLine.size(); i++) { 425 | String User = ((Customer) messobj.userOnLine.elementAt(i)).custName; 426 | lstUserList.addItem(User); 427 | } 428 | Integer a = new Integer(messobj.userOnLine.size()); 429 | lblCount.setText(a.toString()); 430 | // 显示用户进入聊天室的信息 431 | if (messobj.userOnLine.size() > intUserTotal) { 432 | // chenmin 433 | String tempstr = ((Customer) messobj.userOnLine.elementAt(messobj.userOnLine.size() - 1)).custName; 434 | // String tempstr = messobj.userOnLine.elementAt( 435 | // messobj.userOnLine.size() - 1).toString(); 436 | if (!tempstr.equals(strLoginName)) { 437 | taUserMessage.append("【" + tempstr + "】来了" + "\n"); 438 | } 439 | } 440 | // 显示用户离开聊天室的信息 441 | // 显示用户离开聊天室的信息 442 | if (messobj.userOnLine.size() < intUserTotal) { 443 | for (int b = 0; b < user_exit.size(); b++) { 444 | isFound = false; 445 | for (int c = 0; c < messobj.userOnLine.size(); c++) { 446 | String tempstr = ((Customer) user_exit.elementAt(b)).custName; 447 | 448 | if (tempstr.equals(((Customer) messobj.userOnLine.elementAt(c)).custName)) { 449 | isFound = true; 450 | break; 451 | } 452 | } 453 | if (!isFound) // 没有发现该用户 454 | { 455 | String tempstr = ((Customer) user_exit.elementAt(b)).custName; 456 | 457 | if (!tempstr.equals(strLoginName)) { 458 | taUserMessage.append("【" + tempstr + "】走了" + "\n"); 459 | } 460 | } 461 | } 462 | } 463 | user_exit = messobj.userOnLine; 464 | intUserTotal = messobj.userOnLine.size(); 465 | streamtoserver.close(); 466 | streamfromserver.close(); 467 | toServer.close(); 468 | Thread.sleep(3000); 469 | } 470 | 471 | } catch (Exception e) { 472 | @SuppressWarnings("unused") 473 | JOptionPane jop = new JOptionPane(); 474 | JOptionPane.showMessageDialog(null, "不能连接服务器!"); 475 | e.printStackTrace(); 476 | frmChat.dispose(); 477 | // System.out.println(); 478 | // System.out.println(e.getMessage()); 479 | } 480 | 481 | } // run()结束 482 | 483 | private void exitChatRoom() { 484 | // TODO 自动生成方法存根 485 | exit(); 486 | } 487 | 488 | // /////////监听按钮响应////////////// 489 | public void actionPerformed(ActionEvent ae) { 490 | Object source = (Object) ae.getSource(); 491 | if (source.equals(btnTimer)) { 492 | new Clock(); 493 | } 494 | if (source.equals(btnCls)) { 495 | clearMessage(); 496 | } 497 | if (source.equals(btnExit)) { 498 | exit(); 499 | } 500 | if (source.equals(btnSend)) { 501 | sendMessage(); 502 | } 503 | if (source.equals(btnSave)) { 504 | saveMessage(); 505 | } 506 | if (source.equals(lstUserList)) // 双击列表框 507 | { 508 | changeUser(); 509 | } 510 | } // actionPerformed()结束 511 | 512 | // /////////监听窗口关闭响应////////////// 513 | class Windowclose extends WindowAdapter { 514 | public void windowClosing(WindowEvent e) { 515 | exit(); 516 | } 517 | } 518 | 519 | // "清屏"按钮 520 | public void clearMessage() { 521 | taUserMessage.setText(""); 522 | } 523 | 524 | // "退出"按钮 525 | public void exit() { 526 | Exit exit = new Exit(); 527 | exit.exitname = strLoginName; 528 | // 发送退出信息 529 | try { 530 | Socket toServer = new Socket(strServerIp, 1001); 531 | // 向服务器发送信息 532 | ObjectOutputStream outObj = new ObjectOutputStream(toServer.getOutputStream()); 533 | outObj.writeObject(exit); 534 | outObj.close(); 535 | toServer.close(); 536 | 537 | frmChat.dispose(); 538 | // this.destroy(); 539 | } catch (Exception e) { 540 | } 541 | 542 | } // exit()结束 543 | 544 | // "发送"按钮 545 | public void sendMessage() { 546 | Chat chatobj = new Chat(); 547 | chatobj.chatUser = strLoginName; 548 | chatobj.chatMessage = txtMessage.getText(); 549 | chatobj.chatToUser = String.valueOf(cmbUser.getSelectedItem()); 550 | chatobj.whisper = chPrivateChat.isSelected() ? true : false; 551 | chatobj.emote = emote.getSelectedItem().toString(); 552 | // 向服务器发送信息 553 | try { 554 | Socket toServer = new Socket(strServerIp, 1001); 555 | ObjectOutputStream outObj = new ObjectOutputStream(toServer.getOutputStream()); 556 | outObj.writeObject(chatobj); 557 | txtMessage.setText(""); // 清空文本框 558 | outObj.close(); 559 | toServer.close(); 560 | } catch (Exception e) { 561 | } 562 | } // sendMessage()结束 563 | 564 | // "保存"按钮 565 | public void saveMessage() { 566 | try { 567 | FileOutputStream fileoutput = new FileOutputStream(this.strLoginName + "_message.txt", true); 568 | String temp = taUserMessage.getText(); 569 | // System.out.println(temp); 570 | fileoutput.write(temp.getBytes()); 571 | fileoutput.close(); 572 | JOptionPane.showMessageDialog(null, "聊天记录保存在" + this.strLoginName + "_message.txt"); 573 | } catch (Exception e) { 574 | System.out.println(e); 575 | } 576 | 577 | } 578 | 579 | // 将所选用户添加到cmbUser中 580 | public void changeUser() { 581 | 582 | boolean key = true; 583 | String selected = lstUserList.getSelectedItem(); 584 | // JOptionPane.showMessageDialog(null, selected); 585 | for (int i = 0; i < cmbUser.getItemCount(); i++) { 586 | if (selected.equals(cmbUser.getItemAt(i))) { 587 | key = false; 588 | break; 589 | } 590 | } 591 | if (key == true) { 592 | cmbUser.insertItemAt(selected, 0); 593 | } 594 | String head = getUserHead(lstUserList.getSelectedItem()); 595 | // JOptionPane.showMessageDialog(null, head); 596 | cmbUser.setSelectedItem(selected); 597 | 598 | // chenmin 599 | headLabel.setIcon(new ImageIcon("face//" + head + ".JPG")); 600 | } // changeUser()结束 601 | 602 | // chenmin 603 | protected void freshHead() { 604 | // TODO 自动生成方法存根 605 | String head = getUserHead(cmbUser.getSelectedItem().toString()); 606 | // JOptionPane.showMessageDialog(null, head); 607 | // cmbUser.setSelectedItem(selected); 608 | 609 | // chenmin 610 | headLabel.setIcon(new ImageIcon("face//" + head + ".JPG")); 611 | } 612 | 613 | // chenmin 614 | private String getUserHead(String selectedItem) { 615 | // TODO 自动生成方法存根 616 | String head = "oo"; 617 | for (int i = 0; i < messobj.userOnLine.size(); i++) { 618 | String User = ((Customer) messobj.userOnLine.elementAt(i)).custName; 619 | head = ((Customer) messobj.userOnLine.elementAt(i)).custHead; 620 | // System.out.println(User+":"+head); 621 | if (User.equals(selectedItem)) { 622 | break; 623 | } 624 | // lstUserList.addItem(User); 625 | } 626 | return head; 627 | } 628 | 629 | public static void main(String args[]) { 630 | new ChatRoom("测试用户", "127.0.0.1"); 631 | } 632 | 633 | } --------------------------------------------------------------------------------