资源简介
使用swing实现的一个小型的聊天室,可以双击发送文件,用于学习使用
代码片段和文件信息
package cat.client;
import java.applet.applet;
import java.applet.AudioClip;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.objectInputStream;
import java.io.objectOutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URL;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import javax.swing.AbstractListModel;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.Jframe;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ListCellRenderer;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.Border;
import javax.swing.border.titledBorder;
import cat.function.CatBean;
import cat.util.CatUtil;
class CellRenderer extends JLabel implements ListCellRenderer {
CellRenderer() {
setOpaque(true);
}
public Component getListCellRendererComponent(JList list object value
int index boolean isSelected boolean cellHasFocus) {
setBorder(BorderFactory.createEmptyBorder(5 5 5 5));// 加入宽度为5的空白边框
if (value != null) {
setText(value.toString());
setIcon(new ImageIcon(“images//1.jpg“));
}
if (isSelected) {
setBackground(new Color(255 255 153));// 设置背景色
setForeground(Color.black);
} else {
// 设置选取与取消选取的前景与背景颜色.
setBackground(Color.white); // 设置背景色
setForeground(Color.black);
}
setEnabled(list.isEnabled());
setFont(new Font(“sdf“ Font.ROMAN_baseLINE 13));
setOpaque(true);
return this;
}
}
class UUListModel extends AbstractListModel{
private Vector vs;
public UUListModel(Vector vs){
this.vs = vs;
}
@Override
public object getElementAt(int index) {
// TODO Auto-generated method stub
return vs.get(index);
}
@Override
public int getSize() {
// TODO Auto-generated method stub
return vs.size();
}
}
public class CatChatroom extends Jframe {
private static final long serialVersionUID = 6129126
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-12-24 13:10 mblt\
目录 0 2017-12-24 13:10 mblt\CatClient\
文件 295 2017-12-24 13:13 mblt\CatClient\.classpath
文件 385 2012-09-21 20:33 mblt\CatClient\.project
目录 0 2017-12-24 13:10 mblt\CatClient\.settings\
文件 629 2012-09-21 20:33 mblt\CatClient\.settings\org.eclipse.jdt.core.prefs
目录 0 2017-12-24 13:13 mblt\CatClient\bin\
目录 0 2017-12-24 13:13 mblt\CatClient\bin\cat\
目录 0 2017-12-24 13:13 mblt\CatClient\bin\cat\client\
文件 1050 2017-12-24 13:13 mblt\CatClient\bin\cat\client\CatChatroom$1.class
文件 2735 2017-12-24 13:13 mblt\CatClient\bin\cat\client\CatChatroom$2.class
文件 1605 2017-12-24 13:13 mblt\CatClient\bin\cat\client\CatChatroom$3.class
文件 1639 2017-12-24 13:13 mblt\CatClient\bin\cat\client\CatChatroom$4.class
文件 2993 2017-12-24 13:13 mblt\CatClient\bin\cat\client\CatChatroom$5.class
文件 5658 2017-12-24 13:13 mblt\CatClient\bin\cat\client\CatChatroom$ClientInputThread$1.class
文件 3180 2017-12-24 13:13 mblt\CatClient\bin\cat\client\CatChatroom$ClientInputThread$2.class
文件 4443 2017-12-24 13:13 mblt\CatClient\bin\cat\client\CatChatroom$ClientInputThread.class
文件 8919 2017-12-24 13:13 mblt\CatClient\bin\cat\client\CatChatroom.class
文件 1570 2017-12-24 13:13 mblt\CatClient\bin\cat\client\CellRenderer.class
文件 645 2017-12-24 13:13 mblt\CatClient\bin\cat\client\UUListModel.class
目录 0 2017-12-24 13:13 mblt\CatClient\bin\cat\function\
文件 3050 2017-12-24 13:13 mblt\CatClient\bin\cat\function\CatBean.class
文件 784 2017-12-24 13:13 mblt\CatClient\bin\cat\function\ClientBean.class
目录 0 2017-12-24 13:13 mblt\CatClient\bin\cat\login\
文件 727 2017-12-24 13:23 mblt\CatClient\bin\cat\login\CatLogin$1.class
文件 987 2017-12-24 13:23 mblt\CatClient\bin\cat\login\CatLogin$2.class
文件 2854 2017-12-24 13:23 mblt\CatClient\bin\cat\login\CatLogin$3.class
文件 921 2017-12-24 13:23 mblt\CatClient\bin\cat\login\CatLogin$4.class
文件 3534 2017-12-24 13:23 mblt\CatClient\bin\cat\login\CatLogin.class
文件 981 2017-12-24 13:13 mblt\CatClient\bin\cat\login\CatResign$1.class
文件 923 2017-12-24 13:13 mblt\CatClient\bin\cat\login\CatResign$2.class
............此处省略50个文件信息
评论
共有 条评论