資源簡介
供大家學習 不要分哈! 這個聊天系統還有那個銀行系統都是和同學一起做的哈!

代碼片段和文件信息
package?Final_chat;
/*登陸成功之后要創建用戶文件夾,之下有一個history文件夾,里邊的txt文件以對方account命名*/
import?java.awt.BorderLayout;
import?java.awt.Color;
import?java.awt.GridLayout;
import?java.awt.List;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.io.File;
import?java.io.FileInputStream;
import?java.io.FileOutputStream;
import?java.net.Socket;
import?javax.swing.JButton;
import?javax.swing.Jframe;
import?javax.swing.JOptionPane;
import?javax.swing.JPanel;
public?class?Client?extends?Jframe?implements?ActionListenerRunnable{
private?JButton?logoutBt?=?new?JButton(“下線“);
private?JButton?mutichat?=?new?JButton(“群聊“);
private?JButton?beginChat?=?new?JButton(“開始私聊“);
private?JButton?singlechat?=?new?JButton(“私聊已開啟“);
private?boolean?canMutiSelect?=?false;
private?List?userList?=?new?List(150canMutiSelect);
private?boolean?canRUN?=?true;
private?Socket?socket?=?null;
private?String?account;?
private?JPanel?bottomPanel?=?new?JPanel();
private?JPanel?topPanel?=?new?JPanel();
private?List?departmentList?=?new?List(150);
public?Client(String?accountSocket?socketList?userList){
this.account=account;
this.userList=userList;
this.settitle(this.account);
bottomPanel.setLayout(new?GridLayout(11));
topPanel.setLayout(new?GridLayout(11));
//chatLabel.setText(“私聊開啟“);
this.getContentPane().add(topPanel?BorderLayout.NORTH);
this.getContentPane().add(userList?BorderLayout.WEST);
this.getContentPane().add(departmentList?BorderLayout.EAST);
this.getContentPane().add(bottomPanel?BorderLayout.SOUTH);
topPanel.setBackground(new?Color(217228252));
topPanel.add(logoutBt);
topPanel.add(singlechat);
topPanel.add(beginChat);
bottomPanel.setBackground(new?Color(217228252));
bottomPanel.add(mutichat);
//panel.add(chatLabel);
//panel.add(beginMutiChat);
userList.addActionListener(this);
logoutBt.addActionListener(this);
mutichat.addActionListener(this);
beginChat.addActionListener(this);
singlechat.addActionListener(this);
this.setSize(260600);
this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
this.setResizable(false);
this.setVisible(true);
new?Thread(this).start();
this.socket=socket;
}
public?void?run(){
try{
while(canRUN){
InfoPackage?ip?=?SYSTEMIO.receive(socket);
System.out.println(“Purpose?is?“+ip.getPurpose());//getPurpose
if(ip.getPurpose().equals(“MSG“)){
Messageframe?mf?=?new?Messageframe(socketip.getAccount()this.account);
mf.infoTa.append(ip.getMessage()?+?“\r\n“);//新出現一個Messageframe,將收到的信息加到自己那個界面上
?????????????????//將聊天記錄儲存在文件里
????????????????????String?change=““;
????????????????????change=ip.getAccount();
????????????????????ip.setAccount(ip.getTargetAccount());
????????????????????ip.setTargetAccount(change);
Messageframe.saveHistory(ip);
}
else?if(ip.getPurpose().equals(“REFRESH_USERS“)){
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????8506??2009-11-29?14:36??Final_chat\Client.java
?????文件???????8079??2009-11-29?02:04??Final_chat\History.java
?????文件???????1548??2009-11-29?14:26??Final_chat\InfoPackage.java
?????文件???????2988??2009-11-29?07:08??Final_chat\Login.java
?????文件???????6197??2009-11-29?03:59??Final_chat\Messagefr
?????文件???????5275??2009-11-29?06:53??Final_chat\Register.java
?????文件??????11703??2009-11-29?14:36??Final_chat\Server.java
?????文件????????805??2009-11-29?06:49??Final_chat\SYSTEMIO.java
?????目錄??????????0??2009-12-16?15:17??Final_chat
-----------?---------??----------?-----??----
????????????????45101????????????????????9
- 上一篇:小的聊天軟件的Java實現
- 下一篇:JAVA簡易畫圖工具
評論
共有 條評論