您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 广告经营 > javaSwing实现聊天室功能仿qq
JavaSwing实现聊天室功能仿QQ一、说明作者:黄大力(137722697@qq.com),javaSwing实现聊天室功能,仿QQ功能,使用Socket、ServerSocket实现聊天功能。Random随机产生验证码,不区分大小写比较验证码,对MD5加密算法对密码进行加密,使用MySql数据库,JDBC操作,接口,多线程。使用IO技术实现记住密码。JavaSwing实现用户登录模块、注册模块,主页面能显示图片、用户名、用户签名等。二、效果1、登录页面2、注册页面3、主页面4、聊天页面三、代码1、项目目录结构:2、数据库设计createdatabasechat_dbcharactersetutf8;usechat_db;CREATETABLEadmin_tb(aIdintPRIMARYKEY,aAccountvarchar(10)NOTNULL,aPwdvarchar(20)NOTNULL);CREATETABLEregusers_tb(uIdintauto_incrementsPRIMARYKEY,accountvarchar(10)NOTNULL,pwdvarchar(40)NOTNULL,sexchar(1)NOTNULL,addressvarchar(50)NOTNULL,tellvarchar(11)defaultNULL,stateintNOTNULL);CREATETABLErel_tb(rIdintPRIMARYKEY,uIdvarchar(10)NOTNULL,uuIdvarchar(10)NOTNULL);INSERTINTOadmin_tbVALUES(00001,admin,132);INSERTINTOregusers_tbVALUES(10000,'137722697','1234','M','guizhou','12345678901',0);INSERTINTOregusers_tbVALUES(10001,'945124747','1315','F','guizhou','12345678901',0);3、登录页面代码packagecom.qq.view;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.KeyAdapter;importjava.awt.event.KeyEvent;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjava.io.BufferedReader;importjava.io.FileReader;importjava.io.FileWriter;importjava.io.IOException;importjavax.swing.BorderFactory;importjavax.swing.ImageIcon;importjavax.swing.JButton;importjavax.swing.JCheckBox;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JPasswordField;importjavax.swing.JTextField;importjavax.swing.SwingUtilities;importjavax.swing.WindowConstants;importcom.qq.dal.Users;importcom.qq.util.ComStr;importcom.qq.util.RandomYzm;importcom.qq.util.createMD5;/***ThiscodewaseditedorgeneratedusingCloudGarden'sJiglooSWT/SwingGUI*Builder,whichisfreefornon-commercialuse.IfJiglooisbeingused*commercially(ie,byacorporation,companyorbusinessforanypurpose*whatever)thenyoushouldpurchasealicenseforeachdeveloperusingJigloo.*Pleasevisit*acceptanceoftheselicensingterms.ACOMMERCIALLICENSEHASNOTBEEN*PURCHASEDFORTHISMACHINE,SOJIGLOOORTHISCODECANNOTBEUSEDLEGALLYFOR*ANYCORPORATEORCOMMERCIALPURPOSE.*/publicclassLoginextendsjavax.swing.JFrame{privateStringrYzm;//随机产生的验证码privateJButtonlogo;//登录按钮privateJLabellUserName;//显示“用户名:”privateJCheckBoxremPwd;//记住密码复选框privateJLabelregedit;privateJLabeltitle;//标题privateJButtonyzm;//用于显示随机产生的验证码privateJTextFieldinYzm;//用户输入的验证码privateJLabellyzm;//显示“验证码:”privateJPasswordFieldpassword;//密码privateJTextFielduserName;//用户名privateJLabellPwd;//显示“密码:”publicstaticLogininst;/***Auto-generatedmainmethodtodisplaythisJFrame*/publicstaticvoidmain(String[]args){SwingUtilities.invokeLater(newRunnable(){publicvoidrun(){inst=newLogin();inst.setLocationRelativeTo(null);inst.setVisible(true);}});}publicLogin(){super();initGUI();}privatevoidinitGUI(){try{this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);this.setTitle(老地方聊天室);//设置窗体标题this.setIconImage(newImageIcon(getClass().getClassLoader().getResource(\\images\\logo.jpg)).getImage());//设置图标getContentPane().setLayout(null);getContentPane().setBackground(newjava.awt.Color(45,173,210));this.setResizable(false);{logo=newJButton();getContentPane().add(logo);logo.setText(登录);logo.setBounds(107,226,184,33);logo.setFont(newjava.awt.Font(MicrosoftYaHeiUI,1,14));logo.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevt){try{logoActionPerformed(evt);//调用登录按钮事件}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}});}{lUserName=newJLabel();getContentPane().add(lUserName);lUserName.setText(用户名:);lUserName.setBounds(49,80,62,17);lUserName.setFont(newjava.awt.Font(MicrosoftYaHeiUI,1,14));}{lPwd=newJLabel();//密码getContentPane().add(lPwd);lPwd.setText(\u5bc6\u7801\uff1a);lPwd.setBounds(46,134,67,17);lPwd.setFont(newjava.awt.Font(MicrosoftYaHeiUI,1,14));}{userName=newJTextField();getContentPane().add(userName);userName.setBounds(123,77,148,24);}{password=newJPasswordField();getContentPane().add(password);password.setBounds(125,129,146,24);password.addKeyListener(newKeyAdapter(){publicvoidkeyPressed(KeyEventevt){try{passwordKeyPressed(evt);}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}});}{lyzm=newJLabel();getContentPane().add(lyzm);lyzm.setText(验证码:);lyzm.setBounds(45,181,62,17);lyzm.setFont(newjava.awt.Font(MicrosoftYaHeiUI,1,14));}{//随机生成样子码inYzm=newJTextField();getContentPane().add(inYzm);inYzm.setBounds(125,179,146,24);inYzm.addKeyListener(newKeyAdapter(){publicvoidkeyPressed(KeyEventevt){try{inYzmKeyPressed(evt);}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}});}{yzm=newJButton();getContentPane().add(yzm);rYzm=RandomYzm.getYzm();yzm.setText(rYzm);yzm.setBounds(283,179,79,24);yzm.setOpaque(false);yzm.setFont(newjava.awt.Font(MicrosoftYaHeiUI,1,14));yzm.setBorder(BorderFactory.createCompoundBorder(null,null));yzm.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevt){yzmActionPerformed(evt);}});}{remPwd=newJCheckBox();getContentPane().add(remPwd);remPwd.setText(
本文标题:javaSwing实现聊天室功能仿qq
链接地址:https://www.777doc.com/doc-5359831 .html