[code=java]//接上
menu2_2_2 = new JMenuItem("添加聊天群");
menu2_2_2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
showAddGroup();
}
});
menu2_2.add(menu2_2_1);
menu2_2.add(menu2_2_2);
menu2.add(menu2_2);
menu2_3 = new JMenu("好友设置");
menu2_3_1 = new JMenuItem("隐身对其可见");
menu2_3_1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(memberList.getSelectedValue()==null){
alert("请选择好友");
return;
}
String str = memberList.getSelectedValue().toString();
String friendName = str.substring(str.lastIndexOf("(")+1,str.lastIndexOf(")"));
if(friendName.equals(userName)) {
alert("请选择好友!");
return;
}
setVisible(friendName);
}
});
menu2_3_4 = new JMenuItem("取消隐身对其可见");
menu2_3_4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(memberList.getSelectedValue()==null){
alert("请选择好友");
return;
}
String str = memberList.getSelectedValue().toString();
String friendName = str.substring(str.lastIndexOf("(")+1,str.lastIndexOf(")"));
if(friendName.equals(userName)) {
alert("请选择好友!");
return;
}
setDisvisible(friendName);
}
});
menu2_3_2 = new JMenuItem("屏蔽好友");
menu2_3_2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(memberList.getSelectedValue()==null){
alert("请选择好友");
return;
}
String str = memberList.getSelectedValue().toString();
String friendName = str.substring(str.lastIndexOf("(")+1,str.lastIndexOf(")"));
if(friendName.equals(userName)) {
alert("请选择好友!");
return;
}
if(friendName.equals("已屏蔽")){
alert("已对好友设置屏蔽!");
return;
}
setStopful(friendName);
}
});
menu2_3_3 = new JMenuItem("解除屏蔽");
menu2_3_3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(memberList.getSelectedValue()==null){
alert("请选择好友");
return;
}
String str = memberList.getSelectedValue().toString();
String friendName = str.substring(str.lastIndexOf("(")+1,str.lastIndexOf(")"));
if(friendName.equals(userName)) {
alert("请选择好友!");
return;
}
if(!friendName.equals("已屏蔽")){
alert("您还没有屏蔽此好友!");
return;
}
friendName = str.substring(0,str.lastIndexOf("("));
friendName = friendName.substring(friendName.lastIndexOf("(")+1,friendName.lastIndexOf(")"));
setStopless(friendName);
}
});
menu2_3.add(menu2_3_1);
menu2_3.add(menu2_3_4);
menu2_3.add(menu2_3_2);
menu2_3.add(menu2_3_3);
menu2.add(menu2_3);
menuBar.add(menu2);
menu3 = new JMenu(" 查 看 ");
menu3_1 = new JMenuItem("好友资料");
menu3_1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
if(memberList.getSelectedValue()==null){
alert("请选择好友");
return;
}
String value = memberList.getSelectedValue().toString();
showCheckFriend(value.substring(value.lastIndexOf("(")+1,value.lastIndexOf(")")),false);
}
});
menu3.add(menu3_1);
menu3_2 = new JMenuItem("屏蔽信息");
menu3_2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
showStopInfo();
}
});
menu3.add(menu3_2);
menuBar.add(menu3);
menu4 = new JMenu(" 聊 天 ");
menu4_1 = new JMenuItem("开始聊天");
menu4_1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
if(memberList.getSelectedValue()==null){
alert("请选择好友");
return;
}
String str = memberList.getSelectedValue().toString();
String friendName = str.substring(str.lastIndexOf("(")+1,str.lastIndexOf(")"));
if(chat.containsKey(friendName))return;
String nickName = str.substring(0,str.lastIndexOf("("));
if(friendName.equals(userName)) {
alert("请选择好友!");
return;
}
ClientChatWindow c = new ClientChatWindow(friendName,nickName);
chat.put(friendName, c);
}
});
menu4.add(menu4_1);
menu4_2 = new JMenuItem("开始群聊");
menu4_2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
//showChatGroup();
}
});
menu4.add(menu4_2);
menuBar.add(menu4);
friendListLabel = new JLabel("- - 好友列表 - -");
friendListLabel.setBounds(0,0,260,20);
this.add(friendListLabel);
memberList=new JList();
friendListPane = new JScrollPane(memberList);
friendListPane.setBounds(0,20,260,450);
this.add(friendListPane);
model=new DefaultListModel();
for(int i = 0 ; i <allFriend.size();i++){
String stopful="";
if(allFriend.get(i).get("stopful")!=null&&!allFriend.get(i).get("stopful").equals("")) {
stopful=allFriend.get(i).get("stopful").toString();
stopFriend.add(allFriend.get(i).get("friendName").toString());
}
model.addElement((allFriend.get(i).get("nickName")+"("+allFriend.get(i).get("friendName"))+") <"+allFriend.get(i).get("state")+">"+stopful);
if(allFriend.get(i).get("state").equals("在线"))
onNum++;
}
//model.addElement(mySecondName);
allUserName.addElement(userName);
memberList.setModel(model);
memberList.setSelectedIndex(0);
//userCount=model.getSize();
currentNumber = new JLabel();
currentNumber.setBounds(5,475,200,20);
currentNumber.setText("当前在线人数:"+onNum);
this.add(currentNumber);
chat = new HashMap<String, ClientChatWindow>();
chatGroup = new HashMap<String, ClientChatGroupWindow>();
}
public void login(){
try {
login_msg = new JLabel("登录中.....");
login_msg.setBounds(100,200,100,30);
this.add(login_msg);
login_quit = new JButton(" 取 消 登 录 ");
login_quit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
try {
/*-缺少东西-*/
u_socket.close();
} catch (IOException e) {
e.printStackTrace();
}
quit();
}
});
login_quit.setBounds(70,230,100,25);
this.add(login_quit);
u_socket=new Socket("127.0.0.1",8765);
dis=new DataInputStream(u_socket.getInputStream());
dos=new DataOutputStream(u_socket.getOutputStream());
dos.writeUTF(userName+";"+state+password);
msg = dis.readUTF();
boolean b = success();
if(!b){
u_socket.close();
this.dispose();
new ClientInterface(userName,password);
return;
}
while(true){
f = dis.readUTF();
if(f.equals("end")) break;
allFriendAddFriend();
}
showMainWindow();
new Thread(this).start();
} catch (Exception e) {
e.printStackTrace();
}
}
public HashMap allFriendAddFriend(){
friend = new HashMap<String, String>();
f = f.substring(6);
num = Integer.parseInt(f.substring(0,f.indexOf(";")));
len = String.valueOf(num).length();
String friendName = f.substring(len+1,num+len+1);
friend.put("friendName", friendName);
f = f.substring(num+len+1);
num = Integer.parseInt(f.substring(0,f.indexOf(";")));
len = String.valueOf(num).length();
String nickName = f.substring(len+1,num+len+1);
friend.put("nickName",nickName);
f = f.substring(num+len+1);
num = Integer.parseInt(f.substring(0,f.indexOf(";")));
len = String.valueOf(num).length();
String state = f.substring(len+1,num+len+1);
friend.put("state",state);
f = f.substring(num+len+1);
num = Integer.parseInt(f.substring(0,f.indexOf(";")));
len = String.valueOf(num).length();
String stopful = f.substring(len+1,num+len+1);
if(stopful.equals("是")) stopful="(已屏蔽)";
else{stopful="";}
friend.put("stopful", stopful);
allFriend.add(friend);
return friend;
}
public boolean success(){
try{
if(msg.charAt(0)=='#'){
mySecondName = msg.substring(1);
allUserName = new Vector<String>();
allFriend = new Vector<HashMap>();
friend = new HashMap<String, String>();
friend.put("friendName",userName);
friend.put("nickName",mySecondName);
friend.put("state",state);
allFriend.add(friend);
write("收到");
return true;
}
if(msg.charAt(0)=='*'){
return false;
}
}catch(Exception e){
e.printStackTrace();
}
return false;
}
[/code] |
|