-
大小: 401KB文件類型: .zip金幣: 2下載: 0 次發(fā)布日期: 2021-05-12
- 語(yǔ)言: Java
- 標(biāo)簽:
資源簡(jiǎn)介
java局域網(wǎng)聊天室課程設(shè)計(jì)源碼,可直接運(yùn)行

代碼片段和文件信息
package?client;
import?java.awt.BorderLayout;
import?java.awt.Color;
import?java.awt.GridLayout;
import?java.awt.Image;
import?java.awt.Toolkit;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.awt.event.WindowAdapter;
import?java.awt.event.WindowEvent;
import?java.io.BufferedReader;
import?java.io.IOException;
import?java.io.InputStreamReader;
import?java.io.PrintWriter;
import?java.net.Socket;
import?java.util.HashMap;
import?java.util.Map;
import?java.util.StringTokenizer;
import?javax.swing.DefaultListModel;
import?javax.swing.JButton;
import?javax.swing.Jframe;
import?javax.swing.JLabel;
import?javax.swing.JList;
import?javax.swing.JOptionPane;
import?javax.swing.JPanel;
import?javax.swing.JScrollPane;
import?javax.swing.JSplitPane;
import?javax.swing.JTextArea;
import?javax.swing.JTextField;
import?javax.swing.border.titledBorder;
import?user.User;
public?class?ClientPort?{
private?Jframe?frame;
private?JList?userList;
private?JTextArea?textArea;
private?JTextField?textField;
private?JTextField?txt_port;
private?JTextField?txt_hostIp;
private?JTextField?txt_name;
private?JButton?btn_start;
private?JButton?btn_stop;
private?JButton?btn_send;
private?JPanel?northPanel;
private?JPanel?southPanel;
private?JScrollPane?rightScroll;
private?JScrollPane?leftScroll;
private?JSplitPane?centerSplit;
private?DefaultListModel?listModel;
private?boolean?isConnected?=?false;
private?Socket?socket;
private?PrintWriter?writer;
private?BufferedReader?reader;
private?MessageThread?messageThread;//?負(fù)責(zé)接收消息的線程
private?Map?onLineUsers?=?new?HashMap();//?所有在線用戶
//?主方法程序入口
public?static?void?main(String[]?args)?{
new?ClientPort();
}
//?執(zhí)行發(fā)送
public?void?send()?{
if?(!isConnected)?{
JOptionPane.showMessageDialog(frame?“還沒有連接服務(wù)器,無法發(fā)送消息!“?“錯(cuò)誤“
JOptionPane.ERROR_MESSAGE);
return;
}
String?message?=?textField.getText().trim();
if?(message?==?null?||?message.equals(““))?{
JOptionPane.showMessageDialog(frame?“消息不能為空!“?“錯(cuò)誤“
JOptionPane.ERROR_MESSAGE);
return;
}
sendMessage(frame.gettitle()?+?“@“?+?“ALL“?+?“@“?+?message);
textField.setText(null);
}
//?構(gòu)造方法
public?ClientPort()?{
textArea?=?new?JTextArea();
textArea.setEditable(false);
textArea.setForeground(Color.blue);
textField?=?new?JTextField();
txt_port?=?new?JTextField(“6666“);
txt_hostIp?=?new?JTextField(“127.0.0.1“);
txt_name?=?new?JTextField(“小倩“);
btn_start?=?new?JButton(“連接“);
btn_stop?=?new?JButton(“斷開“);
btn_send?=?new?JButton(“發(fā)送“);
listModel?=?new?DefaultListModel();
userList?=?new?JList(listModel);
northPanel?=?new?JPanel();
northPanel.setLayout(new?GridLayout(1?7));
northPanel.add(new?JLabel(“端口“));
northPanel.add(txt_port);
northPanel.add(new?JLabel(“服務(wù)器IP“));
northPanel.add(txt_hostIp);
northPanel.add(new?JLabel(“姓名“))
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-09-01?08:11??NChat\
?????文件?????????301??2016-08-31?23:11??NChat\.classpath
?????文件?????????381??2016-08-31?23:11??NChat\.project
?????目錄???????????0??2016-08-31?23:11??NChat\.settings\
?????文件?????????598??2016-08-31?23:11??NChat\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2016-09-01?08:12??NChat\bin\
?????目錄???????????0??2016-09-01?08:18??NChat\bin\client\
?????文件?????????660??2016-09-01?08:21??NChat\bin\client\ClientPort$1.class
?????文件?????????657??2016-09-01?08:21??NChat\bin\client\ClientPort$2.class
?????文件????????2271??2016-09-01?08:21??NChat\bin\client\ClientPort$3.class
?????文件????????1448??2016-09-01?08:21??NChat\bin\client\ClientPort$4.class
?????文件?????????787??2016-09-01?08:21??NChat\bin\client\ClientPort$5.class
?????文件????????3721??2016-09-01?08:21??NChat\bin\client\ClientPort$MessageThread.class
?????文件????????8236??2016-09-01?08:21??NChat\bin\client\ClientPort.class
?????文件???????75332??2016-09-01?08:05??NChat\bin\client\test.jpg
?????目錄???????????0??2016-09-01?08:18??NChat\bin\server\
?????文件?????????776??2016-09-01?08:19??NChat\bin\server\ServerPort$1.class
?????文件?????????657??2016-09-01?08:19??NChat\bin\server\ServerPort$2.class
?????文件?????????660??2016-09-01?08:19??NChat\bin\server\ServerPort$3.class
?????文件????????2528??2016-09-01?08:19??NChat\bin\server\ServerPort$4.class
?????文件????????1785??2016-09-01?08:19??NChat\bin\server\ServerPort$5.class
?????文件????????4621??2016-09-01?08:19??NChat\bin\server\ServerPort$ClientThread.class
?????文件????????3058??2016-09-01?08:19??NChat\bin\server\ServerPort$ServerThread.class
?????文件????????8228??2016-09-01?08:19??NChat\bin\server\ServerPort.class
?????文件???????75332??2016-09-01?08:05??NChat\bin\server\test.jpg
?????目錄???????????0??2016-08-31?23:33??NChat\bin\user\
?????文件?????????757??2016-09-01?07:58??NChat\bin\user\User.class
?????目錄???????????0??2016-09-01?08:12??NChat\image\
?????文件???????75332??2016-09-01?08:05??NChat\image\test.jpg
?????目錄???????????0??2016-09-01?08:12??NChat\src\
?????目錄???????????0??2016-09-01?08:18??NChat\src\client\
............此處省略7個(gè)文件信息
評(píng)論
共有 條評(píng)論