欢迎来到天天文库
浏览记录
ID:9304979
大小:470.50 KB
页数:10页
时间:2018-04-27
《一个简单的java聊天室程序功能齐全》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、聊天室使用说明一、开发语言:Java高级语言编程二、开发环境:JCreatorPro三、运行环境:JCreatorPro四、使用流程:首先在JCreatorPro环境中编译,然后打开运行即可。效果图浏览:-10-u服务器端代码importjava.io.*;importjava.awt.*;importjava.awt.event.*;importjava.net.*;importjava.util.Collection;importjava.util.Hashtable;importjava.util.Iterator;publicclas
2、sChatServerextendsFrame{TextAreata=newTextArea(20,52);//消息接收显示框TextFieldtf=newTextField(32);//消息编写框Buttonb=newButton("发送");//发送消息按钮-10-Buttonstart=newButton("启动服务");ServerSocketserver=null;TextFieldportInput=newTextField("4444",2);ListuserList=newList(21);ButtonrefreshUser=
3、newButton("刷新用户列表");//Vectorusers=newVector();Hashtablehash=newHashtable();publicChatServer(){super("丁丁猫聊天室服务器端");ta.setBackground(newColor(100,190,50));//设置背景色ta.setForeground(Color.red);//设置字体颜色ta.setEditable(false);//文本框不可编辑//this.add(ta,BorderLayout.NORTH);Panelp=newPan
4、el(newFlowLayout(FlowLayout.LEFT));//第一个Panel,放置输入数据p.add(newLabel("Port"));p.add(portInput);p.add(start);p.add(tf);p.add(b);Panelpleft=newPanel(newBorderLayout());//第二个Panel,显示登陆数据pleft.add(ta,BorderLayout.NORTH);pleft.add(p,BorderLayout.CENTER);Panelpright=newPanel(newBor
5、derLayout());userList.setBackground(newColor(10,160,90));userList.setForeground(Color.orange);Panelpb=newPanel();//第三个Panel,显示客户端输入数据pb.add(refreshUser);pright.add(pb,BorderLayout.CENTER);pright.add(userList,BorderLayout.NORTH);//this.add(p,BorderLayout.CENTER);this.add(ple
6、ft,BorderLayout.CENTER);this.add(pright,BorderLayout.EAST);this.setResizable(true);//能调节窗口大小MyActionListenerlis=newMyActionListener();this.addWindowListener(lis);-10-start.addActionListener(lis);b.addActionListener(lis);refreshUser.addActionListener(lis);this.pack();this.sh
7、ow();}publicstaticvoidmain(String[]args){ChatServers=newChatServer();}publicvoidshowUserList(){userList.clear();Collectioncol=hash.keySet();Iteratorit=col.iterator();inti=0;while(it.hasNext()){Stringname=(String)it.next();userList.add(name);i++;}this.setTitle("丁丁猫聊天室服务器端-当前
8、在线"+i+"位用户");}//广播消息publicvoidbroadCast(Stringmsg){Collectioncol=hash.values();Ite
此文档下载收益归作者所有