基于JAVA的网络聊天室(BS)

上传者: liutangcheng88 | 上传时间: 2023-12-22 16:11:03 | 文件大小: 48KB | 文件类型: RAR
部分代码如下:client: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package client; /** * * @author Administrator */ import java.awt.*; import java.io.*; import java.net.*; import java.applet.*; import java.util.Hashtable; public class ClientChat extends Applet implements Runnable { Socket socket=null; DataInputStream in=null; DataOutputStream out=null; InputNameTextField 用户提交昵称界面=null; ChatArea 用户聊天界面=null; Hashtable listTable; Label 提示条; Panel north, center; Thread thread; public void init() { int width=getSize().width; int height=getSize().height; listTable=new Hashtable(); setLayout(new BorderLayout()); 用户提交昵称界面=new InputNameTextField(listTable); int h=用户提交昵称界面.getSize().height; 用户聊天界面=new ChatArea("",listTable,width,height-(h+5)); 用户聊天界面.setVisible(false); 提示条=new Label("正在连接到服务器,请稍等...",Label.CENTER); 提示条.setForeground(Color.red); north=new Panel(new FlowLayout(FlowLayout.LEFT)); center=new Panel(); north.add(用户提交昵称界面); north.add(提示条); center.add(用户聊天界面); add(north,BorderLayout.NORTH); add(center,BorderLayout.CENTER); validate(); } public void start() { if(socket!=null&&in!=null&&out!=null) { try { socket.close(); in.close(); out.close(); 用户聊天界面.setVisible(false); } catch(Exception ee) { } } try { socket = new Socket(this.getCodeBase().getHost(), 6666); in=new DataInputStream(socket.getInputStream()); out=new DataOutputStream(socket.getOutputStream()); } catch (IOException ee) { 提示条.setText("连接失败"); } if(socket!=null) { InetAddress address=socket.getInetAddress(); 提示条.setText("连接:"+address+"成功"); 用户提交昵称界面.setSocketConnection(socket,in,out); north.validate(); } if(thread==null) { thread=new Thread(this); thread.start(); } } public void stop() { try { socket.close(); thread=null; } catch(IOException e) { this.showStatus(e.toString()); } } public void run() { while(thread!=null) { if(用户提交昵称界面.get能否聊天()==true) { 用户聊天界面.setVisible(true); 用户聊天界面.setName(用户提交昵称界面.getName()); 用户聊天界面.setSocketConnection(socket,in,out); 提示条.setText("祝聊天愉快!"); center.validate(); break; } try { Thread.sleep(100); } catch(Exception e) { } } } }

文件下载

资源详情

[{"title":"( 31 个子文件 48KB ) 基于JAVA的网络聊天室(BS)","children":[{"title":"网络聊天室(BS)","children":[{"title":"Client","children":[{"title":"test","children":null,"spread":false},{"title":"applet.policy <span style='color:#111;'> 54B </span>","children":null,"spread":false},{"title":"dist","children":[{"title":"Client.jar <span style='color:#111;'> 14.79KB </span>","children":null,"spread":false},{"title":"README.TXT <span style='color:#111;'> 1.41KB </span>","children":null,"spread":false}],"spread":true},{"title":"manifest.mf <span style='color:#111;'> 85B </span>","children":null,"spread":false},{"title":"src","children":[{"title":"client","children":[{"title":"InputNameTextField.java <span style='color:#111;'> 3.73KB </span>","children":null,"spread":false},{"title":"ChatArea.java <span style='color:#111;'> 5.98KB </span>","children":null,"spread":false},{"title":"ClientChat.java <span style='color:#111;'> 3.20KB </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"build","children":[{"title":"ClientChat.html <span style='color:#111;'> 694B </span>","children":null,"spread":false},{"title":"classes","children":[{"title":"client","children":[{"title":"ChatArea.class <span style='color:#111;'> 5.59KB </span>","children":null,"spread":false},{"title":"ClientChat.class <span style='color:#111;'> 3.95KB </span>","children":null,"spread":false},{"title":"InputNameTextField.class <span style='color:#111;'> 4.35KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true},{"title":"build.xml <span style='color:#111;'> 3.28KB </span>","children":null,"spread":false},{"title":"nbproject","children":[{"title":"build-impl.xml <span style='color:#111;'> 32.39KB </span>","children":null,"spread":false},{"title":"private","children":[{"title":"private.xml <span style='color:#111;'> 633B </span>","children":null,"spread":false},{"title":"private.properties <span style='color:#111;'> 98B </span>","children":null,"spread":false}],"spread":true},{"title":"project.properties <span style='color:#111;'> 1.80KB </span>","children":null,"spread":false},{"title":"project.xml <span style='color:#111;'> 576B </span>","children":null,"spread":false},{"title":"genfiles.properties <span style='color:#111;'> 455B </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"Server","children":[{"title":"test","children":null,"spread":false},{"title":"dist","children":[{"title":"Server.jar <span style='color:#111;'> 5.85KB </span>","children":null,"spread":false},{"title":"README.TXT <span style='color:#111;'> 1.41KB </span>","children":null,"spread":false}],"spread":true},{"title":"manifest.mf <span style='color:#111;'> 85B </span>","children":null,"spread":false},{"title":"src","children":[{"title":"server","children":[{"title":"ChatServer.java <span style='color:#111;'> 6.09KB </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"build","children":[{"title":"classes","children":[{"title":"server","children":[{"title":"ChatServer.class <span style='color:#111;'> 1.49KB </span>","children":null,"spread":false},{"title":"Server_thread.class <span style='color:#111;'> 3.59KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true},{"title":"build.xml <span style='color:#111;'> 3.28KB </span>","children":null,"spread":false},{"title":"nbproject","children":[{"title":"build-impl.xml <span style='color:#111;'> 32.39KB </span>","children":null,"spread":false},{"title":"private","children":[{"title":"private.xml <span style='color:#111;'> 413B </span>","children":null,"spread":false},{"title":"private.properties <span style='color:#111;'> 98B </span>","children":null,"spread":false}],"spread":true},{"title":"project.properties <span style='color:#111;'> 1.77KB </span>","children":null,"spread":false},{"title":"project.xml <span style='color:#111;'> 576B </span>","children":null,"spread":false},{"title":"genfiles.properties <span style='color:#111;'> 455B </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true}]

评论信息

免责申明

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