import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.border.Border;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import java.util.*;
class FindFriend2 extends JFrame {//查找好友类
JLabel jLabel1 = new JLabel();
JButton find2 = new JButton();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JList list2;
///////////////////以下是好友的呢称,性别等信息
Vector nickname = new Vector();
Vector sex = new Vector();
Vector place = new Vector();
Vector jicq = new Vector();
Vector ip = new Vector();
Vector pic = new Vector();
Vector status = new Vector();
Vector emails = new Vector();
Vector infos = new Vector();
//以下临时保存好友的呢称,性别等信息
Vector tmpjicq = new Vector();//jicqid
Vector tmpname = new Vector();//jicqname
Vector tmpip = new Vector();//ip
Vector tmppic = new Vector();//pic info
Vector tmpstatus = new Vector();//status
Vector tmpemail = new Vector();
Vector tmpinfo = new Vector();
//以下创建网络相关变量
Socket socket;
//Socket client;
BufferedReader in;
PrintWriter out;
p2p peo;
int myid;
String serverhost;
int servport;
//DatagramPacket sendPacket;
//DatagramSocket sendSocket;
int sendPort = 8000;
//////////////////
JPopupMenu findmenu = new JPopupMenu();
JMenuItem look = new JMenuItem();
JMenuItem add = new JMenuItem();
public FindFriend2(int whoami, String host, int port) {//查找好友类构造函数
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
serverhost = host;
servport = port;
myid = whoami;
jbInit();
} catch (Exception e) {
e.printStackTrace();
}//以下与服务器连接
try {
socket = new Socket(InetAddress.getByName(serverhost), servport);
in = new BufferedReader(new InputStreamReader(socket
.getInputStream()));
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
socket.getOutputStream())), true);
//sendSocket = new DatagramSocket();
} catch (IOException e1) {
}
}
private void jbInit() throws Exception {//以下是程序界面
jLabel1.setText("下面是在线的朋友");
jLabel1.setBounds(new Rectangle(11, 11, 211, 18));
this.getContentPane().setLayout(new FlowLayout());
find2.setText("查找");
find2.setBounds(new Rectangle(8, 289, 79, 29));
find2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
find2_mouseClicked(e);
}
});
jButton1.setText("next");
jButton1.setBounds(new Rectangle(110, 288, 79, 29));
jButton2.setText("up");
jButton2.setBounds(new Rectangle(211, 285, 79, 29));
jButton3.setText("cancel");
jButton3.setBounds(new Rectangle(317, 289, 79, 29));
// nickname=new Vector();
// sex=new Vector();
// place=new Vector();
ListModel model = new FindListModel(nickname, sex, place);//列表模型
ListCellRenderer renderer = new FindListCellRenderer();
list2 = new JList(model);
list2.setSize(200, 200);
list2.setBackground(new Color(255, 255, 210));
list2.setAlignmentX((float) 1.0);
list2.setAlignmentY((float) 1.0);
list2.setCellRenderer(renderer);
list2.setVisibleRowCount(7);
list2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent evt){
if(list2.getSelectedIndex()!=-1)
jlist1mouseclicked(evt);
}
});
look.setText("查看资料");
add.setText("加为好友");
add.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
add_mousePressed(e);
}
});
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(new JScrollPane(list2));
this.getContentPane().add(find2, null);
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jButton2, null);
this.getContentPane().add(jButton3, null);
findmenu.add(look);
findmenu.add(add);
}//以下是关闭本窗口
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
//this.dispose();
this.setVisible(false);
}
}
//以下向服务器发送查找好友请求
void find2_mouseClicked(MouseEvent e) {
out.println("find");
DefaultListModel mm = (DefaultListModel) list2.getModel();
/////////////////find friend info
try {
String s = " ";
//从服务器读取好友信息
do {
s = in.readLine();
if (s.equals("over"))
break;
nickname.add(s);
sex.add(in.readLine());
place.add(in.readLine());
ip.add(in.readLine());
emails.add(in.readLine());
infos.add(in.readLine());
} while (!s.equals("over"));
/////////////end find info
//read their jicqno
int theirjicq, picinfo, sta;
for (int x = 0; x < nickname.size(); x++) {
theirjicq = Integer.parseInt(in.readLine());
//System.out.println(theirjicq);
jicq.add(new Integer(theirjicq));
picinfo = Integer.parseInt(in.readLine());
pic.add(new Integer(picinfo));
sta = Integer.parseInt(in.readLine());
//System.out.println(sta);
status.add(new Integer(sta));
//System.out.println(jicq.get(x));
}
//在列表中显示
for (int i = 0; i < nickname.size(); i++) {
mm.addElement(new Object[] { nickname.get(i), sex.get(i),
place.get(i) });
}//for
} catch (IOException e4) {
System.out.println("false");
}
}
//显示查找好友菜单
void list2_mousePressed(MouseEvent e) {
findmenu.show(this, e.getX() + 20, e.getY() + 50);
}
private void jlist1mouseclicked(java.awt.event.MouseEvent evt) {
// add your handling code here:
if(evt.getClickCount() == 2) {
int dd;
dd=list2.getSelectedIndex();
// new p2p(nickname.get(dd).toString(),myname,socket);
}
}
/////////////add frined
//以下将添加的好友存储在临时矢量
void add_mousePressed(MouseEvent e) {
//add friend to database
int dd;
dd = list2.getSelectedIndex();
tmpjicq.add(jicq.get(dd));
tmpname.add(nickname.get(dd));
tmpip.add(ip.get(dd));
tmppic.add(pic.get(dd));
tmpstatus.add(status.get(dd));
tmpemail.add(emails.get(dd));
tmpinfo.add(infos.get(dd));
//以下向服务器发送添加好友请求
out.println("addfriend");
out.println(jicq.get(dd));
out.println(myid);
//try { //以下告诉客户将其加为好友
String whoips;
String s = "oneaddyou" + myid;
s.trim();
System.out
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
即时通讯工具(局域网内通讯) (632个子文件)
t2.bmp 600KB
t2.bmp 600KB
BordTop.bmp 32KB
BordTop.bmp 32KB
BordBottom.bmp 30KB
BordBottom.bmp 30KB
ButtonSenddown.bmp 3KB
ButtonSendover.bmp 3KB
ButtonSendnormal.bmp 3KB
ButtonSenddown.bmp 3KB
ButtonSendover.bmp 3KB
ButtonSendnormal.bmp 3KB
ButtonRightHideover.bmp 488B
ButtonRightHideover.bmp 488B
MainWin.class 26KB
ChatFrame.class 12KB
ServerThread.class 10KB
FindFriend2.class 8KB
Register.class 7KB
p2p.class 6KB
New.class 6KB
ClientProc.class 4KB
MessageNote.class 4KB
TrayIconUtil.class 4KB
clientThread.class 3KB
Server.class 3KB
ChatServer.class 3KB
serv.class 3KB
FindListCellRenderer.class 2KB
NameAndPicListCellRenderer.class 2KB
MainWin$4.class 2KB
HeadpicCellRenderer.class 2KB
MyTextPane.class 2KB
NameAndPicListModel.class 1KB
FindListModel.class 1KB
TrayIconUtil$1.class 1KB
MainWin$3.class 1KB
ChatFrame$1.class 1KB
PopupListener.class 1002B
ChatFrame$2.class 958B
p2p$2.class 854B
MessageNote$2.class 803B
HeadPicCombobox.class 770B
FindFriend2$2.class 752B
ExitAction.class 750B
MessageNote$1.class 712B
p2p$1.class 647B
p2p$3.class 638B
p2p$4.class 615B
MainWin$2.class 614B
FindFriend2$1.class 598B
MainWin_sendmessage_mouseAdapter.class 596B
FindFriend2$3.class 596B
Register$1.class 587B
MainWin$20.class 586B
MainWin$13.class 584B
MainWin$16.class 583B
MainWin$6.class 583B
ChatFrame$3.class 583B
MainWin$8.class 583B
MainWin$17.class 582B
MainWin_cancel_mouseAdapter.class 581B
MainWin_direct_mouseAdapter.class 581B
MainWin$12.class 581B
MainWin$14.class 581B
MainWin$7.class 581B
MainWin$15.class 581B
MainWin$18.class 580B
MainWin$19.class 580B
MainWin$11.class 580B
MainWin$5.class 579B
MainWin$10.class 579B
MainWin$1.class 577B
MainWin$9.class 577B
MainWin_list_mouseAdapter.class 575B
MainWin_ok_mouseAdapter.class 569B
New$2.class 556B
New$1.class 554B
New$3.class 553B
MessageNote$3.class 497B
ChatFrame$4.class 410B
.classpath 350B
Thumbs.db 530KB
Thumbs.db 530KB
TrayIcon.dll 24KB
1110.GIF 8KB
1110.GIF 8KB
BordTop.GIF 8KB
BordTop.GIF 8KB
tip.GIF 6KB
tip.GIF 6KB
BordBottom.GIF 4KB
BordBottom.GIF 4KB
ButtonSenddown.GIF 2KB
ButtonSenddown.GIF 2KB
login.GIF 1KB
login.GIF 1KB
reg.GIF 1KB
reg.GIF 1KB
cancle.GIF 1KB
共 632 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
- zuoxiaozong2012-09-20可以用。。但是太简便了。。。
- zkq9859182011-11-14用java写的,不过文件有损坏,不能用了
雕虫大计
- 粉丝: 32
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功