关于山寨QQ的java的源代码.docx

上传人:李司机 文档编号:5535738 上传时间:2023-07-19 格式:DOCX 页数:25 大小:51.78KB
返回 下载 相关 举报
关于山寨QQ的java的源代码.docx_第1页
第1页 / 共25页
关于山寨QQ的java的源代码.docx_第2页
第2页 / 共25页
关于山寨QQ的java的源代码.docx_第3页
第3页 / 共25页
关于山寨QQ的java的源代码.docx_第4页
第4页 / 共25页
关于山寨QQ的java的源代码.docx_第5页
第5页 / 共25页
点击查看更多>>
资源描述

《关于山寨QQ的java的源代码.docx》由会员分享,可在线阅读,更多相关《关于山寨QQ的java的源代码.docx(25页珍藏版)》请在三一办公上搜索。

1、关于山寨QQ的java的源代码Java是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由SunMicrosystems公司于1995年5月推出的Java程序设计语言和Java平台(即JavaSE,JavaEE,JavaME)的总称。Java技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于个人PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。在全球云计算和移动互联网的产业环境下,JaVa更具备了显著优势和广阔前景。文库里没有关于山寨QQ的java的源代码,只能看了视频整理自己写了,特免费分享。文档说明:根据java教学视频韩顺平.

2、循序渐进学java.从入门到精通(第8794讲)整理得源相关代码。代码调试无误,下载后调试有误的可评论留言联系。image中图片附录在源代码后面。工程文件夹:,一一.o.一.-V/赘ZTestQqClient,src田com.qq.client.modelI:*t)QqclientConServerjavaJ2)QqClientUserjava田com.qq.dienttoolsJJ)ClientConServerThreadjavatManageclientConServerThreadjavalmManageQqChatjavaT)ManageQqFriendIjstjava,com.qq

3、.dient.viewljj)QqChatJavaQqCIientLoginjavamQqFriendListjava,田mon:jj)Messagejava02)MessageTypejavat川Userjava3JRESystemLibraryJavaSE-1.6&image国clear.gif阖denglu.gif国mm.jpg3qqgif屈quxiao.gif三Thumbs.db国tou.gif溷xiangdao.gifr三rotnyDuxpiwiSioW2TestQqClient濯2TestQqServerSSrCJBmonMessagejava团MessageTypeJava辽IU

4、serjavacom.qq.server.db加com.qq.server.model功ManageCIientThreadjavaMyQqServerjavamSerConClientThreadjavacom.qq.server.tls曲com.qq.server.view团MyServerFramejavaBJRESystemLibraryJavaSE-1.6(源代码)/*这是客户端连接服务器的后台*/packagecom.qq.client.model;importcom.qq.client.tools.*;importjava.util.*;.*;importjava.io.*;mo

5、n.*;publicclassQqC1ientConServerpublicSockets;发送第一次请求publicbooleansendLoginInfoToServer(Objecto)(booleanb=false;try(/System.out.println(,kk);s=newSocket(127.0.0.,9988);ObjectOutputStreamoos=newObjectOutputStream(s.getOutputStream();oos.writebject(o);ObjectInputStreamois=newObjectInputStream(s.getInp

6、utStream();Messagems=(Message)ois.readObject();这里就是验证用户登录的地方if(ms.getMesType().equa!s(1)就创建个该qq号和服务器端保持通讯连接得线程ClientConServerThreadccst=newClientConServerThread(三);启动该通讯线程ccst.start();ManageClientConServerThread.addClientConServerThread(User)o).getUserId(),ccst);b=true;)else关闭Scokets.close();)catch(

7、Exceptione)e.printStackTrace();/TODO:handleexceptionfinally1returnb;)publicvoidSendInfoToServer(Objecto)(*trySockets=newSocket(127.0.0.1,9999);)catch(Exceptione)e.printStackTrace();/TODO:handleexception)finally)*/11packagecom.qq.client.model;mon.*;publicclassQqCIientUserpublicbooleancheckUser(Useru)

8、(returnnewQqClientConServerQ.sendLoginlnfoToServer(u);)*这是客户端和服务器端保持通讯的线程.*/packagecom.qq.client.tools;importjava.io.*;.*;importcom.qq.client.view.QqChat;importcom.qq.client.view.QqFriendList;mon.*;publicclassClientConServerThreadextendsThreadprivateSockets;构造函数publicClientConSen,erThread(Sockets)1t

9、his.s=s;)publicvoidrun()(while(true)(不停的读取从服务器端发来的消息try(ObjectInputStreamois=newObjectInputStream(s.getInputStream();Messagem=(Message)ois.readObject();System.out.println(读取到从服务发来的消息+m.getSender()+给+m.getGetter()+内容+m.getCon();if(m.getMesType().equals(MessageType.message_comm_mes)(把从服务器获得消息,显示到该显示的聊

10、天界面QqChatqqChat=ManageQqChat.getQqChat(m.getGetter()+m.getSender();显示qqChat.showMessage(m);(elseif(m.getMesType().equals(MessageType.message_ret_onLineFriend)(SyStem.out.println(“客户端接收到”+m.getCon();Stringcon=m.getCon();Stringfriends=con.split();Stringgetter=m.getGetter();System.out.println(,getter=,

11、+getter);/修改相应的好友列表.QqFriendListqqFriendList=ManageQqFriendList.getQqFriendList(getter);/if(qqFriendList)更新在线好友.if(qqFriendList!=null)(qqFriendList.upateFriend(m);1)catch(Exceptione)e.printStackTrace();/TODO:handleexception1)publicSocketgetS()returns;)publicvoidsetS(Sockets)this.s=s;)*这是一个管理客户端和服务器保

12、持通讯的线程类*/packagecom.qq.client.tools;importjava.util.*;publicclassManageciicntConServerThreadprivatestaticHashMaphm=newHashMap();把创建好的ClientConServerThread放入到IhmpublicstaticvoidaddClientConServerThread(Stringqqld,ClientConServerThreadccst)(hm.put(qqld,ccst);1可以通过qqld取得该线程publicstaticClientConServerTh

13、readgetClientConServerThread(Stringqqld)(return(ClientCOnSerVerThread)hm.get(qqld);)*这是一个管理用户聊天界面的类*/packagecom.qq.client.tools;importjava.util.*;importcom.qq.client.view.*;publicclassManageQqChatprivatestaticHashMaphm=nevHashMap();加入publicstaticvoidaddQqChat(StringIoginIdAnFriendId5QqChatqqChat)(hm

14、.put(loginIdAnFriendId,qqChat);)取出publicstaticQqChatgetQqChat(StringIoginIdAnFriendId)(return(QqChat)hm.get(loginIdAnFriendId);)*管理好友、黑名单,界面类*/packagecom.qq.clicnt.tools;importjava.util.*;importjava.io.*;importcom.qq.client.view.*;publicclassManageQqFriendListprivatestaticHashMaphm=newHashMap();publ

15、icstaticvoidaddQqFriendList(Stringqqid,QqFriendListqqFriendList)hm.put(qqid,qqFriendList);1publicstaticQqFriendListgetQqFriendList(Stringqqld)(return(QqFriendList)hm.get(qqId);11* 这是与好友聊天的界面* 因为客户端,要处于读取的状态,因此我们把它做成一个线程* /packagecom.qq.client.view;importcom.qq.client.tools.*;importcom.qq.client.mode

16、l.*;mon.*;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.io.*;publicclassQqChatextendsJFrameimplementsActionListenerfJTextAreajta;JTextFieldjtf;JButtonjb;JPaneljp;Stringownerld;Stringfriendld;publicstaticvoidmain(Stringargs)/TODOAuto-generatedmethodstub/QqChatqqChat=newQqChat

17、(,);publicQqChat(Stringownerld,Stringfriend)(this.ownerld=ownerld;this.friendld=friend;jta=newJTextArea();jtf=newJTextField(15);jb=newJBUttOn(发送);jb.addActionListener(Ihis);jp=newJPanel();jp.add(jtf);jp.add(jb);this.add(jta,Center);this.add(jp,South);this.setTitle(ownerId+正在和+friend+聊天);this.setlcon

18、lmage(newImagelcon(imageqq.gif,).getlmage();this.setSize(300,200);this.setVisible(true);)写一个方法,让它显示消息publicvoidshowMessage(Messagem)(Stringinfo=m.getSender()+对+m.getGetter()+说:+m.getCon()+rr;this.jta.append(info);1publicvoidactionPerformed(ActionEventarg)/TODOAuto-generatcdmethodstubif(arg0.getSourc

19、e()=jb)(如果用户点击了,发送按钮Messagem=newMessage();m.setMesType(MessageType.message_comm_mes);/川最后一步m.setSender(this.ownerId);m.setGetter(this.friendld);m.setCon(jtf.getText();m.setSendTime(newjava.util.Date().toString();发送给服务器.try(ObjectOutputStreamoos=newObjectOutputStream(ManageCIicntConServerThread.getCI

20、ientConServerThread(ownerId).getS().getOutputStream();oos.writebject(m);catch(Exceptione)e.printStackTrace();/TODO:handleexception1)/publicvoidrun()/TODOAuto-generatedmethodstub/while(true)(try(/读取如果读不到就等待./ObjectInputStreamObjectInputStream(QqClientConServer.s.getInputStream();/Messagem=(Message)oi

21、s.readObject();/显示ois=new/Stringinfo=m.getSender()+对+m.getGetter()+/this.jta.append(info);/catch(Exceptione)/e.printStackTrace();/TODO:handleexception/1/H说:+m.getCon()+rn;*功能:qq客户端登录界面*/packagecom.qq.client.view;mon.*;importcom.qq.client.tools.*;importjava.io.*;importjavax.swing.*;importcom.qq.clien

22、t.model.QqClientUser;mon.User;importjava.awt.*;importjava.awt.event.*;publicclassQqClientLoginextendsJFrameimplementsActionListenerf定义北部需要的组件JLabeljbll;定义中部需要的组件.中部有三个JPaneI,有一个叫选项卡窗口管理JTabbedPanejtp;JPaneljp2,jp3,jp4;JLabeljp2Jbl1,jp2Jbl2,jp2Jbl3,jp2Jbl4;JButtonjp2_jbl;JTextFieldjp2Jtf;JPasswordFie

23、ldjp2Jpf;JCheckBoxjp2Jcb1Jp2jcb2;定义南部需要的组件JPaneljpl;JButtonjplJbl,jpI_jb2jpl_jb3;publicstaticvoidmain(Stringargs)/TODOAuto-generatedmethodstubQqClientLoginqqCIientLogin=newQqClientLoginO;)publicQqClientLoginO处理北部jbll=newJLabel(newImagelcon(image/tou.gif);处理中部jp2=newJPanel(newGridLayout(3,3);jp2jbll=

24、newJLabel(QQ号码JLabeI.CENTER);jp2Jb12=newJLabcl(QQ密码,JLabeLCENTER);jp2Jb13=newJLabel(忘记密码,JLabeLCENTER);jp2_jbl3.SetForeground(ColoEblue);jp2Jb14=newJLabe1(申请密码保护,JLabeLCENTER);jp2,jbl=newJButton(newImageIcon(imageclear.gi);jp2Jtf=newJTextFieldO;jp2_jpf=newJPasswordField();jp2_jcb1=newJCheckBox(隐身登录)

25、;jp2,jcb2=newJCheCkBOX(记住密码);把控件按照顺序加入到jp2jp2.add(jp2Jbll);jp2.add(jp2Jtf);jp2.add(jp2Jbl);jp2.add(jp2Jb12);jp2.add(jp2Jpf);jp2.add(jp2Jb13);jp2.add(jp2Jcbl);jp2.add(jp2Jcb2);jp2.add(jp2Jb14);创建选项卡窗口jtp=newJTabbedPaneO;jtp.add(QQ号码”,jp2);jp3=newJPanel();jtp.add(手机号码”,jp3);jp4=newJPanel();jtp.add(“电子

26、邮件”Jp4);处理南部jpl=newJPanel();jpl_jbl=newJButton(newImagelcon(imagedenglu.gif);响应用户点击登录jpl_jb1.addActionListener(Ihis);jpl-jb2=newJButton(newImagelcon(imagequxiao.gif);jpljb3=newJButton(newImagelcon(imagexiangdao.gif,);把三个按钮放入到jpljpl.add(jpljbl);jpl.add(jpljb2);jpl.add(jpljb3);this.add(jbll,North);thi

27、s.add(jtp,Center);/.把jpl放在南部this.add(jpl,South);this.setSize(350,240);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);1publicvoidactionPerformed(ActionEventarg)/TODOAuto-generatcdmethodstub如果用户点击登录if(arg0.getSource()=jp1_jb1)(QqClientUserqqClientUser=newQqClicntUserO;Useru=

28、newUser();u.setUserId(jp2Jtf.getText().trim();u.setPasswd(newString(jp2_jpf.getPassword();if(qqCIientUser.checkUser(u)(try(把创建好友列表的语句提前.QqFriendListqqList=newQqFriendList(u.getUserId();ManageQqFriendList.addQqFriendList(u.getUserId(),qqList);/发送一个要求返回在线好友的请求包.ObjectOutputStreamoos=newObjectOutputStr

29、eam(ManageCIicntConServerThread.getClientConSen,erThread(u.getUserId().getS().getOutputStream();做j个MessageMessagem=newMessage();m.setMesType(MessageType.message_get_onLineFriend);/指明我要的是这个qq号的好友情况.m.setSender(u.getUserId();oos.writebject(m);catch(Exceptione)e.printStackTrace();/TODO:handleexception关

30、闭掉登录界面this.dispose();)elseJOptionPane.showMessageDialog(this,户名密码错误);111*我的好友列表,(也包括陌生人,黑名单)*/packagecom.qq.client.view;importcom.qq.client.tools.*;mon.Message;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassQqFriendListextendsJFrameimplementsActionListener,MouseListener/处理第一张

31、卡片.JPaneljphyI,jphy2,jphy3;JButtonjphyjbl,jphyjb2,jphyjb3;JScrollPanejspl;Stringowner;处理第二张卡片(陌生人)JPaneljpmsrl,jpmsr2,jpmsr3;JButtonjpmsr_Jbl,jpmsr_Jb2,jpmsr_Jb3;JScrollPanejsp2;JLabeljbls;把整个JFrame设置成CardLayoutCardLayoutcl;publicstaticvoidmain(Stringargs)/TODOAuto-generatedmethodstub/QqFriendListqq

32、FriendList=newQqFriendListO;1更新在线的好友情况publicvoidupateFriend(Messagem)(StringonLineFriend=m.getCon().split(,);for(inti=0;ionLineFriend.length;i+)(jblsInteger.parseInt(onLineFriendi)-l.setEnabled(true);11publicQqFriendListCStringownerld)(this.owner=ownerld;处理第一张卡片(显示好友列表)jphy.jb1=newJBUtton(我的好友);jphy

33、_jb2=newJBUttOn(陌生人);jphyJb2.addActionListener(this);jphy_jb3=newJBUttOn(黑名单”);jphy1=newJPanel(newBorderLayoutO);假定有50个好友jphy2=newJPanel(newGridLayOUt(501,4,4);/给jphy2,初始化50好友.jbls=newJLabel50;fbr(inti=O;ijbls.Iength;i+)(jb1si=newJLabel(i+l+newImagelcon(,imagemm.jpg),JLabeI.LEFT);jb1si.setEnabled(fa

34、lse);if(jb1si.getText().equa!s(ownerId)(jblsi.setEnabled(true);jb1si.addMouseListener(this);jphy2.add(jblsi);1jphy3=newJPanel(newGridLayout(2,l);把两个按钮加入到jphy3jphy3.add(jphyjb2);jphy3.add(jphyjb3);jspl=newJScrollPane(jphy2);对jphyl,初始化jphyl.add(jphy_jb1,North);jphy1.add(jsp1,Center*);jphy1.add(jphy3,S

35、outh1);处理第二张卡片jpmsjjbl=newJButton(我的好友);jpmsr,jb1.addActionListenerCthis);jpmsr_jb2=newJButton(陌生人);jpmsrjb3=newJBUttOn(“黑名单”);jpmsrl=newJPaneI(newBorderLayoutO);假定有20个陌生人jpmsr2=newJPanel(newGridLayout(20,1,4,4);给jphy2,初始化20陌生人.JLabeljbls2=newJLabeI20;for(inti=0;ijbls2.length;1+)(jb1s2i=newJLabel(i+

36、1+,newImageIcon(imagemm.jpg),JLabel.LEFT);jpmsr2.add(jb1s2i);)jpmsr3=newJPanel(newGridLayout(2,l);把两个按钮加入到jphy3jpmsr3.add(jpmsr-jbl);jpmsr3.add(jpmsrjb2);jsp2=newJScroIIPane(jpmsr2);对jphyl,初始化jpmsrl.add(jpmsr3,North);jpmsrl.add(jsp2,Center);jpmsrl.add(jpmsr_jb3,South);cl=newCardLayout();this.setLayo

37、ut(cl);this.add(jphyl,);this.add(jpmsrl,2);在窗口显示自己的编号.this.setTitle(ownerId);this.setSize(250,600);this.setVisible(true);1publicvoidactionPerformed(ActionEventarg)/TODOAuto-generatedmethodstub如果点击了陌生人按钮,就显示第二张卡片if(arg0.getSource()=jphyjb2)(cl.show(this.getContentPane(),2);(elseif(arg0.getSource()=jp

38、msr_jb1)cl.show(this.getContentPane(),1);)publicvoidmouseCIicked(MouseEventarg)/TODOAuto-generatedmethodstub响应用户双击的事件,并得到好友的编号.if(arg0.getClickCount()=2)(得到该好友的编号StringfriendNo=(JLabel)arg0.getSource().getText();/System.out.println(你希望和+friendNo+聊天);QqChatqqChat=newQqChat(this.owner,friendNo);/把聊天界面

39、加入到管理类ManageQqChat.addQqChat(this.owner+friendNo,qqChat);11publicvoidmouseEntered(MouseEventarg)/TODOAuto-generatedmethodstubJLabeljl=(JLabel)arg0.getSource();jLsetForeground(ColoLred);)publicvoidmouseExited(MouseEventarg)/TODOAuto-generatedmethodstubJLabelji=(JLabel)arg0.getSource();JLsetForeground

40、(ColoEblack);1publicvoidmousePressed(MouseEventarg)/TODOAuto-generatedmethodstub1publicvoidmouseReleased(MouseEventarg)/TODOAuto-generatedmethodstub)mon;publicclassMeSSageimplementsjava.io.SerializableprivateStringmesType;privateStringsender;privateStringgetter;privateStringcon;privateStringsendTime

41、;publicStringgetSenderOreturnsender;)publicvoidsetSender(Stringsender)this.sender=sender;publicStringgetGetter()returngetter;publicvoidsetGetter(Stringgetter)this.getter=getter;publicStringgetCon()returncon;publicvoidsetCon(Stringcon)this.con=con;publicStringgetSendTime()returnsendTime;publicvoidset

42、SendTime(StringsendTime)this.sendTime=sendTime;publicStringgetMesType()returnmesType;publicvoidsetMesType(StringmesType)this.mesType=mesType;*定义包的种类*/mon;publicinterfaceMessageTypeStringmessage-succeed=1明是登陆成功1StringmessageOgin_fail=2;表明登录失败Stringmessage_comm_mes=3;普通信息包Stringmessage-geLonLineFriend

43、=4;/要求在线好友的包Stringmessage_ret_onLineFriend=5,返回在线好友的包*这是用户信息类*/mon;publicclassUserimplementsjava.io.SerializableprivateStringuserid;privateStringpasswd;publicStringgetUserId()returnuserid;)publicvoidsetUserId(Stringuserid)this.userld=userid;)publicStringgetPasswd()returnpasswd;)publicvoidsetPasswd(Stringpasswd)this.passwd=passwd;)mon;publicclassMeSSageimplementsjava.io.SerializableprivateStringmesType;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号