ImageVerifierCode 换一换
格式:DOCX , 页数:22 ,大小:22.55KB ,
资源ID:7352496      下载积分:1 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-7352496.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(java聊天小程序课程设计文档格式.docx)为本站会员(b****4)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

java聊天小程序课程设计文档格式.docx

1、3.用户可以配置连接后显示的用户名。4.当服务器端开启的话,用户可以随时登录和注销。5.用户可以向所有人或某一个人发送消息。三、 系统运行环境本程序基于 java 和 Eclipse 开发环境, 可以在一般的装有 windows 系统的主 机上运行。Eclipse 是一个开放源代码的软件开发项目, 专注于为高度集成的工具开发提 供一个全功能的、具有商业品质的工业平台。它主要由 Eclipse 项目、 Eclipse 工具项目和 Eclipse 技术项目三个项目组成, 具体包括四个部分组成 Eclipse Platform、JDT CDT和PDE JDT支持Java幵发、CDT支持C幵发、PDE

2、用来支持发平台。它提供建造块和构造并运行集成软件幵发工具的基础。四、功能需求描述本系统针对局域网进行联机聊天。聊天室分为服务器端和客户端两部分,服 务器端程序主要负责侦听客户端发来的信息,客户端需要登陆到服务器端才可以 实现正常的聊天功能。本系统主要实现如下功能:其界面主要采用了包,包以及 包等。程序实现了聊天室的基本功能,其中有:1、 启动服务器。2、 进入客户端界面。3、 登录聊天室。4、 发送信息(实现按回车键发送消息)。5、 关闭服务器。服务器:在特定端口上进行侦听,等待客户端连接。向已经连接到服务器端的用户发送系统消息。当停止服务时,断幵所有的用户连接。系统运行稳定、安全可靠。一台主

3、机只能启动一个服务器。客户端:连接到已经幵启聊天服务的服务器端。当服务器端幵启后,用户可以发表聊天信息。用户可以向所有人或某一个人发送消息。系统运行稳定、安全可靠五、总体设计聊天系统的设计跟普通网站设计有着许多不同的地方,普通网站设计所考虑 的因素,例如,普通网站需要对布局进入大量美化以及动画设计等等,而聊天室 只要提供满足访客双方直接实时聊天即可。因此,在设计聊天系统的过程中,必 须要考虑好以下几个设计要点:在In ternet上的聊天程序一般都是以服务器提供服务端连接响应, 使用者通过客户端程序登录到服务器,就可以与登录在同一服务器上的用户交谈,这是一 个面向连接的通信过程。因此,程序要在

4、 TCP/IP环境下,实现服务器端和客户端两部分程序。1.首先通过继承JFrame类构造服务器界面。2.设计客户端程序使其能够完成正常的通信功能3.设计侦听程序,使其显示登录的 ip地址端口号,以及用户昵称,通过侦听按钮可以调用客户端程序,实现聊天功能。六、系统模块结构图主要功能框架如下图所示:代码:客户端A客户端C丿 T 、上服务器 发客户端 .J退出线 纟线 送服聊1) package chat;import .*;public class ActionProcess implements Runnable private ChatClient client;String name=;St

5、ring sendtoname=String sendtoID;String filename=String filepath=public ActionProcess(ChatClient client) =client;public void action(ActionEvent e)throws Exception if()=tryelseString addr=( 请输入服务器 IP:);InetAddress address=(addr);InetSocketAddress socketAddress=new InetSocketAddress(address,5555);=new

6、Thread(this);catch(IOException ee) if()=filesendServer filesendserver=new filesendServer();();catch (Exception ee) (); if()=try filesendClient filesendclient=new filesendClient();catch (Exception ee) catch (IOException e1) (0);if ( 表情) else em += 着 if()=if(s!=null)catch(IOException e1)sendtoID=( 请输入

7、对方 ID: sendtoname=( 请输入对方姓名 : if(s! public void run()String s=null; while(true) catch(IOException e) catch(Exception ep) break;(2) package chat; import .*;public class Client public static void main(String args)new ChatClient();class ChatClient extends Frame implements ActionListener, Runnable publi

8、c Button listen,connection,sendtoall,sendtoone,exit,filesend; public JComboBox emote;public TextField inputName,inputContent;public TextArea chatResult;public Socket socket=null;public DataInputStream in=null;public DataOutputStream out=null;public Thread thread;ChatClient()socket=new Socket();Box b

9、ox1=();listen=new Button( 作为服务器监听 connection=new Button( 连接服务器 filesend=new Button( 发送文件 exit=new Button( 退出 sendtoone=new Button( 私聊 (false);inputName=new TextField(6);(new Color(162,231,250);inputContent=new TextField(22);chatResult= new TextArea(, 17,20,;JLabel jlname=new JLabel( 输入昵称 (jlname);(i

10、nputName);(listen);(connection);(filesend);(exit);Box box2=();emote = new JComboBox();(new DefaultComboBoxModel(new String 表情 , 微笑 甜笑 惊喜 嘻嘻 扮酷 嘿嘿 傻笑 好奇 媚眼 鬼脸 陶醉 害羞 生气 嚷嚷 发怒 伤心 高明 菜鸟 问号 狂笑 大哭 示爱 呻吟 想想 );JLabel jlintput = new JLabel( 输入聊天内容 (jlintput);(inputContent);(emote);(sendtoall);(sendtoone);(th

11、is);Box box3=();(chatResult);thread=new Thread(this);Box box0=();(10);(box1);(box3);(box2);add(box0);setBounds(10,30,500,400);setBackground(new Color(80,212,248);setVisible(true);validate();addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) (0););public void actionPerform

12、ed(ActionEvent e) ActionProcess actionProcess=new ActionProcess(this);(e); catch (Exception e1) public void run()while(true) s=();(n+s);catch(IOException e) 与服务器断开连接 catch(Exception ep)break;(3)package chat;public class ChatServerpublic static void main(String args)throws Exception ServerSocket svSo

13、cket =null;Vector threads = new Vector();svSocket = new ServerSocket(5555);catch (Exception ex) return;tryint nid = 0;while(true)Socket socket = ();ServerThread st = new ServerThread(socket,threads);(nid+);(st);new Thread(st).start();for(int i=0;i ();i+)ServerThread temp = (ServerThread)(i);catch(Ex

14、ception ex)class ServerThread implements Runnableprivate Vector threads;private Socket socket = null;private DataInputStream in = null;private DataOutputStream out = null;private int nid;public ServerThread(Socket socket,Vector threads) = socket;= threads;in = new DataInputStream(); out = new DataOu

15、tputStream();catch (Exception ex) public void run() try while(true) String receive = (); if(receive = null) return;if( 黯然下线了 ) for(int i=0;i+) ServerThread st = (ServerThread)(i); (*+receive+ else if( 上线了 ServerThread st = (ServerThread)(i);+getID()+: +receive);else if( 监听中 )* 说 大家 elseint temp=(int

16、 temp1=(String tempS=(temp+1,temp1);int i=(tempS);st = (ServerThread)(getID();ServerThread st = (ServerThread)(getID();try ();public void write(String msg)synchronized(out) try(msg);public int getID()return ;public void setID(int nid)= nid;(4)public class filesendClient public void filesend() throws

17、 ExceptionString sendtoIP=( 请输入对方 IP: Socket socket = new Socket(sendtoIP, 1234); BufferedReader br = new BufferedReader( new InputStreamReader();PrintStream ps = new PrintStream();File file = getFile();();String msg = (); 已存在 .equals(msg)(null, 文件已存在 , 请不要重复上传 ! return;long finishLen = (msg);FileIn

18、putStream fis = new FileInputStream(file);OutputStream out = ();byte buffer = new byte1024;int len;(finishLen);while(len = (buffer) != -1)(buffer, 0, len);public File getFile() throws Exception File file=null;boolean flag=false;while(flag=false)String filepath=( 请输入要上传的路径 :file = new File(filepath);

19、if(!() 您输入的路径不存在 , 请重新输入! flag=false;else if() 占不支持文件夹上传 ! 请输入一个 文件路径!else flag=true;return file;(5)public class filesendServerpublic void filereceive() throws ExceptionServerSocket serverSocket = new ServerSocket(1234); 服务已启动 , 绑定 1234 端口!new fileServerThread(socket).start();class fileServerThread

20、extends ThreadSocket socket;public fileServerThread(Socket socket) = socket;public void run() FileOutputStream fos = null;BufferedReader br = new BufferedReader(new InputStreamReader();String fileName = ();long fileLen = ();File dir = new File(uploadFile file = new File(dir,fileName);if() & () = fil

21、eLen) (String time = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss).format(new Date();long start = ();InputStream in = ();fos = new FileOutputStream(file, true);= -1)if() = fileLen)long end = ();time = new SimpleDateFormat( 上传成功 catch (IOException e) if(fos != null)运行结果:将 5 个 Java 源文件:、。分别编译这 5 个 Java 源文件,或运行“ javac *.java 命令,编译全部的源文件,然后运行连接服务器的主类, 即。服务器启动成功 结果分析:在进入聊天室之前必须先启动服务器,实现服务器端的连接。然后运行结果分析:

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2