java 大一课程设计 qq聊天程序

上传者: liweijing_08 | 上传时间: 2021-12-14 21:45:57 | 文件大小: 442KB | 文件类型: -
java 大一课程设计 qq聊天程序socket=new Socket(); textPanel.send.setEnabled(false); thread=new Thread(this); setVisible(true); validate(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==save) { savefile.setVisible(true); if(savefile.getFile()!=null) { try{ File file=new File(savefile.getDirectory(),savefile.getFile()); FileWriter tofile=new FileWriter(file); BufferedWriter out=new BufferedWriter(tofile); out.write(textPanel.getWholeText(), 0, textPanel.getWholeText().length()); out.close(); tofile.close(); } catch(IOException e2){} } } else if(e.getSource()==doodle) { thePaint.setVisible(true); } else if(e.getSource()==Disconnect) { if(socket.isConnected()) { try{ ps.writeUTF("QUIT:"); ps.flush(); socket.close();}catch(IOException ee){System.out.println("无法关闭");} } setTitle("用户"+name+"离线"); textPanel.send.setEnabled(false); nameList.removeAll(); nameLable.setText("在线用户: "+"人数: "+(nameList.getItemCount())); } else if(e.getSource()==connect) { try//请求和服务器建立套接字连接 { if(socket.isConnected()){} else { InetAddress address=InetAddress.getLocalHost(); InetSocketAddress socketAddress=new InetSocketAddress(address,8080); socket.connect(socketAddress); reader=new DataInputStream(socket.getInputStream()); ps=new DataOutputStream(socket.getOutputStream()); out=new ObjectOutputStream(socket.getOutputStream()); in=new ObjectInputStream(socket.getInputStream()); ps.writeUTF(name);//开始即传输用户名 ps.flush(); setTitle("用户"+name+"在线"); thread.start(); } }catch(IOException ee){} } else if(e.getSource()==groupChat) { groupMode=true; condition.setText("群 聊\n"); textPanel.send.setEnabled(true); } else if(e.getSource()==privateChat) { groupMode=false; condition.setText("私 聊\n"); textPanel.send.setEnabled(true); } else if(e.getSource()==nameList) { if(!groupMode) { indexName=nameList.getSelectedItem(); condition.setText("私 聊\n与"+nameList.getSelectedItem()+"聊天中\n"); } } else if(e.getSource()==textPanel.send) { if(e.getSource()==textPanel.send) { textPanel.text=textPanel.in.getText(); Font f=textPanel.in.getFont(); textPanel.out.setFont(f); Color c=textPanel.in.getForeground(); textPanel.out.setForeground(c); textPanel.in.setText(""); if(!groupMode) { textPanel.out.append("\n"+"我说:"+textPanel.text+"\n"); } else { textPanel.out.append("\n"); } System.out.println("文本输出~~"); String text=textPanel.text; if(groupMode) { StringBuffer msg=new StringBuffer("MSG:"); msg.append(text); String s=msg.toString(); try{ ps.writeUTF(s); ps.flush();}catch(IOException ee){System.out.println("输出文本错误");} System.out.println("成功输出"); } else { StringBuffer msg=new StringBuffer("MSGTOONE:"); msg.append(indexName+":"+text); String s=msg.toString(); try{ ps.writeUTF(s); ps.flush();}catch(IOException ee){System.out.println("输出文本错误");} System.out.println("成功输出"); } }

文件下载

评论信息

  • wenhan159 :
    不管怎么样,还是几个不错的程
    2013-05-09
  • lianqi15571 :
    基础,可能这些东西对于我这种人不适合吧,适合初学者
    2013-04-10
  • scu_daiwei :
    可以学习借鉴,以前学的都忘了,现在靠看这些程序来熟悉
    2012-09-19
  • sheoopp :
    不管怎么样,还是几个不错的程序
    2012-08-10

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明