-
大小: 772.48 KB文件類型: .rar金幣: 1下載: 0 次發(fā)布日期: 2024-12-17
- 語言: Java
- 標(biāo)簽:
資源簡介
本聊天室為本人修改創(chuàng)作,并附帶有開發(fā)文檔,內(nèi)含可行性分析、需求分析、詳細(xì)設(shè)計(jì)等,功能完善,界面美觀,適合作為課程設(shè)計(jì)之用
代碼片段和文件信息
import?java.awt.*;
import?java.awt.event.*;
import?javax.swing.*;
import?javax.swing.event.*;
import?java.io.*;
import?java.net.*;
/***?聊天客戶端的主框架類*/
public?class?ChatClient?extends?Jframe?implements?ActionListener{
String?ip?=?“127.0.0.1“;//連接到服務(wù)端的ip地址
int?port?=?8888;//連接到服務(wù)端的端口號
String?userName?=?“花好月圓“;//用戶名
int?type?=?0;//0表示未連接,1表示已連接
Image?icon;//程序圖標(biāo)
JComboBox?combobox;//選擇發(fā)送消息的接受者
JTextArea?messageShow;//客戶端的信息顯示
JScrollPane?messageScrollPane;//信息顯示的滾動條
JLabel?expresssendToLabelmessageLabel?;
JTextField?clientMessage;//客戶端消息的發(fā)送
JCheckBox?checkbox;//私聊
JButton?clientMessageButton;//發(fā)送消息
JTextField?showStatus;//顯示用戶連接狀態(tài)
Socket?socket;
objectOutputStream?output;//網(wǎng)絡(luò)套接字輸出流
objectInputStream?input;//網(wǎng)絡(luò)套接字輸入流
ClientReceive?recvThread;
//建立工具欄
JToolBar?toolBar?=?new?JToolBar();
//建立工具欄中的按鈕組件
JButton?loginButton;//用戶登錄
JButton?logoffButton;//用戶注銷
JButton?userButton;//用戶信息的設(shè)置
JButton?connectButton;//連接設(shè)置
JButton?exitButton;//退出按鈕
//框架的大小
Dimension?faceSize?=?new?Dimension(400?600);
JPanel?downPanel?;
GridBagLayout?girdBag;
GridBagConstraints?girdBagCon;
public?ChatClient(){
init();//初始化程序
//添加框架的關(guān)閉事件處理
this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
this.pack();
//設(shè)置框架的大小
this.setSize(faceSize);
//設(shè)置運(yùn)行時窗口的位置
Dimension?screenSize?=?Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(?(int)?(screenSize.width?-?faceSize.getWidth())?/?2
?(int)?(screenSize.height?-?faceSize.getHeight())?/?2);
this.setResizable(false);
this.settitle(“客戶端“);?//設(shè)置標(biāo)題
//程序圖標(biāo)
icon?=?getImage(“icon.gif“);
this.setIconImage(icon);?//設(shè)置程序圖標(biāo)
show();
}
/***?程序初始化函數(shù)*/
public?void?init(){
Container?contentPane?=?getContentPane();
contentPane.setLayout(new?BorderLayout());
//添加菜單欄
//初始化按鈕
loginButton?=?new?JButton(“登錄“);
logoffButton?=?new?JButton(“注銷“);
userButton??=?new?JButton(“用戶設(shè)置“?);
connectButton??=?new?JButton(“連接設(shè)置“?);
exitButton?=?new?JButton(“退出“?);
//將按鈕添加到工具欄
toolBar.add(userButton);
toolBar.add(connectButton);
toolBar.addSeparator();//添加分隔欄
toolBar.add(loginButton);
toolBar.add(logoffButton);
toolBar.addSeparator();//添加分隔欄
toolBar.add(exitButton);
contentPane.add(toolBarBorderLayout.NORTH);
checkbox?=?new?JCheckBox(“私聊“);
checkbox.setSelected(false);
//初始時
loginButton.setEnabled(true);
logoffButton.setEnabled(false);
//添加按鈕的事件偵聽
loginButton.addActionListener(this);
logoffButton.addActionListener(this);
userButton.addActionListener(this);
connectButton.addActionListener(this);
exitButton.addActionListener(this);
combobox?=?new?JComboBox();
combobox.insertItemAt(“所有人“0);
combobox.setSelectedIndex(0);
messageShow?=?new?JTextArea();
messageShow.setEditable(false);
//添加滾動條
messageScrollPane?=?new?JScrollPane(messageShow
JScrol
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????????5??2009-03-25?20:54??第二組\源程序\客戶端\1.bat
?????文件??????10067??2009-04-28?09:13??第二組\源程序\客戶端\ChatClient.java
?????文件???????1744??2006-05-25?20:35??第二組\源程序\客戶端\ClientReceive.java
?????文件???????3517??2006-04-14?00:21??第二組\源程序\客戶端\ConnectConf.java
?????文件???????1005??2009-04-28?06:56??第二組\源程序\客戶端\icon.GIF
?????文件???????2804??2009-04-28?07:00??第二組\源程序\客戶端\UserConf.java
?????文件??????????5??2009-03-25?20:54??第二組\源程序\服務(wù)端\1.bat
?????文件??????10002??2009-04-28?08:38??第二組\源程序\服務(wù)端\ChatServer.java
?????文件???????1005??2009-04-28?06:56??第二組\源程序\服務(wù)端\icon.gif
?????文件????????238??2006-04-11?23:11??第二組\源程序\服務(wù)端\Node.java
?????文件???????2842??2006-04-12?00:06??第二組\源程序\服務(wù)端\PortConf.java
?????文件???????1572??2006-05-25?19:59??第二組\源程序\服務(wù)端\ServerListen.java
?????文件???????3977??2009-04-28?11:25??第二組\源程序\服務(wù)端\ServerReceive.java
?????文件???????1409??2009-04-28?07:27??第二組\源程序\服務(wù)端\Userli
?????文件?????710144??2009-05-22?11:33??第二組\用戶手冊.doc
?????文件?????222720??2009-05-22?11:33??第二組\聊天室程序設(shè)計(jì).doc
?????目錄??????????0??2009-05-07?17:32??第二組\源程序\客戶端
?????目錄??????????0??2009-05-07?17:32??第二組\源程序\服務(wù)端
?????目錄??????????0??2009-05-07?17:32??第二組\源程序
?????目錄??????????0??2009-05-07?18:27??第二組
-----------?---------??----------?-----??----
???????????????973056????????????????????20
評論
共有 條評論