




已阅读5页,还剩27页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
32 / 32河南工业大学课 程 设 计课程设计名称: java qq聊天系统 专 业 班 级 : 学 生 姓 名 : xiaoyang 学 号 : 指 导 教 师 : 王高平 课程设计时间: 2016.7.7 计科 专业课程设计任务书学生姓名Xiaoyang专业班级计科f1401学号题 目qq聊天系统课题性质其它课题来源自拟课题指导教师王高平同组姓名主要内容 Eclipse,mysql,java 网络通信,输入输出流,类的对象,以及封装,多态实现qq聊天功能,局域网下的qq聊天系统任务要求 综合运用java知识,实现对输入输出流的运用,以及对面向对象的基本运用,与此同时还要学会数据库连接的使用,以及基本语法,jdbc。参考文献1詹英.数据库技术与应用M.北京:清华大学出版社.2008.9-142黄德才.数据库原理及其应用教程.M.北京:科学出版社.2007.12-33龚沛曾,杨志强. 数据库技术与应用M.北京 高等教育出版社.20084任满杰.数据库实用教程M.电子工业出版社.20065王珊,萨师煊.数据库系统概论M.高等教育出版社出版.2005审查意见指导教师签字:教研室主任签字: 年 月 日 说明:本表由指导教师填写,由教研室主任审核后下达给选题学生,装订在设计(论文)首页1 需求分析运用java语言实现一个qq聊天局域网系统,主要功能实现信息的相互交流,整个程序分三个大模块,第一个模块是服务器端的设计,第二个模块是客户端的实现,第三个模块是数据库连接的实现。主要实现一个客户端发送串字符信息,另一端客户端能接受(在一个局域网下),同时建立了一个数据库(mysql),用于注册用户,同时存储用户的信息,以及找回密码要用到的密保问题答案。2 概要设计通过密保找回密码错误 登录 成功?否!否!注册账号无该账号是好友列表一个好友聊天框另一个好友聊天框服务器主要类:JqqF类:主要是登录窗口Cell类:按钮类Findpassword.java:找回密码类Look:注册窗口Lookpassword.java:查看密码窗口Register.java:注册账号类JavaMysql.java:数据库类,连接数据库。3 运行环境(软、硬件环境) Windows,64位pc机,jvm(java虚拟机)4 开发工具和编程语言Eclipse,java5 详细设计Server.java(实现一个小型的服务器)package ;import java.io.*;import .*;import java.util.*;public class Sever boolean started = false;ServerSocket ss = null; List clients = new ArrayList(); public static void main(String args) new Sever().start(); public void start() try ss = new ServerSocket(9999);started = true; catch (BindException e) System.out.println(端口使用中.);System.out.println(请关掉相关程序并重新运行服务器!);System.exit(0); catch (IOException e) e.printStackTrace();try while (started) Socket s = ss.accept();Client c = new Client(s);System.out.println(a client connected!);new Thread(c).start();clients.add(c);/ dis.close(); catch (IOException e) e.printStackTrace(); finally try ss.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace(); class Client implements Runnable private Socket s;private DataInputStream dis = null;private DataOutputStream dos = null;private boolean bConnected = false;public Client(Socket s) this.s = s;try dis = new DataInputStream(s.getInputStream();dos = new DataOutputStream(s.getOutputStream();bConnected = true; catch (IOException e) e.printStackTrace();public void send(String str) try dos.writeUTF(str); catch (IOException e) clients.remove(this);System.out.println(对方退出了!我从List里面去掉了!);/ e.printStackTrace();public void run() /线程体try while (bConnected) String str = dis.readUTF();System.out.println(str);for (int i = 0; i clients.size(); i+) Client c = clients.get(i);c.send(str); catch (EOFException e) System.out.println(Client closed!); catch (IOException e) e.printStackTrace(); finally try if (dis != null)dis.close();if (dos != null)dos.close();if (s != null) s.close();/ s = null; catch (IOException e1) e1.printStackTrace();JqqF类:登录的窗口类package ;import java.awt.Color;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;public class JqqF extends JFrame implements MouseListener private static final long serialVersionUID = 1L;public static void main(String args) JqqF f = new JqqF();public static JTextField name = new JTextField(20);JLabel nameLab = new JLabel(输入qq号:);public static JPasswordField nam = new JPasswordField(20);JLabel nameLa = new JLabel(输入qq密码:);String path5 = pic/x.png;/ 背景图片ImageIcon background5 = new ImageIcon(path5);cell but = new cell(background5);Font fnt = new Font(Serief, Font.BOLD, 15);String path4 = pic/l.png; ImageIcon background4 = new ImageIcon(path4); cell bt = new cell(background4); String path3 = pic/b.png; ImageIcon background3 = new ImageIcon(path3); cell bt2 = new cell(background3); String path2 = pic/qq3.png; ImageIcon background2 = new ImageIcon(path2);JLabel label2 = new JLabel(background2);public JqqF() super(qq测试);this.setSize(500, 334);this.setLocation(300, 200);this.setVisible(true);String path = pic/qq.png;/ 背景图片ImageIcon background = new ImageIcon(path);/ 把背景图片显示在一个标签里面JLabel label = new JLabel(background);label.setLayout(null);/ 把标签的大小位置设置为图片刚好填充整个面板label.setBounds(0, 0, this.getWidth(), this.getHeight();/ 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明JPanel imagePanel = (JPanel) this.getContentPane();imagePanel.setOpaque(false);/ 把背景图片添加到分层窗格的最底层作为背景nameLab.setFont(fnt);nameLab.setForeground(Color.yellow);nameLa.setFont(fnt);nameLa.setForeground(Color.yellow);nameLab.setBounds(160, 120, 100, 30);bt.setBounds(360, 120, 72, 30);bt.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) register x = new register(););name.setBounds(250, 120, 100, 30);nameLa.setBounds(160, 160, 100, 30);nam.setBounds(250, 160, 100, 30);bt2.setBounds(360, 160, 72, 30);bt2.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) new findpassword(););/ / nam.setColumns(20) ;label2.setBounds(65, 120, 88, 83);but.setBounds(185, 210, 147, 30);but.addMouseListener(this);label.add(nameLab);label.add(bt);label.add(bt2);label.add(nam);label.add(nameLa);label.add(label2);label.add(name);label.add(but);this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE);this.setResizable(false);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/ 让组件可见public void mouseClicked(MouseEvent e) char a = nam.getPassword();String s = new String(a);/ System.out.print(s);String b = 1;Statement st = null;ResultSet rs = null;boolean t = false;boolean x = false;Connection con = null;String sql = SELECT name,mibao,password FROM qq;try con = new JavaMysql().connnecton();st = con.createStatement();rs = st.executeQuery(sql); catch (ClassNotFoundException e2) / TODO Auto-generated catch blocke2.printStackTrace(); catch (SQLException e2) / TODO Auto-generated catch blocke2.printStackTrace();try while (rs.next() String qq = rs.getString(name);/匹配用户名String password1 = rs.getString(password);/匹配密码if (qq.equals(name.getText() t = true;if (password1.equals(nam.getText() x = true;con.close();st.close();rs.close(); catch (SQLException e1) / TODO Auto-generated catch blocke1.printStackTrace();if (t) if (x) JqqF2 f1 = new JqqF2();/好友列表在这里显示this.setVisible(false);/登录窗口消失f1.setVisible(true);/好友列表出现 else new passworderror(); else new look();Overridepublic void mousePressed(MouseEvent e) / TODO Auto-generated method stubOverridepublic void mouseReleased(MouseEvent e) / TODO Auto-generated method stubOverridepublic void mouseEntered(MouseEvent e) / TODO Auto-generated method stubOverridepublic void mouseExited(MouseEvent e) / TODO Auto-generated method stub;Passerror类:密码错误提示窗口package ;import javax.swing.JFrame;import javax.swing.JLabel;public class passworderror extends JFrameJLabel b = new JLabel(密码错误);public passworderror()this.add(b);this.setSize(100,100);this.setLocation(300, 500);this.setVisible(true);this.setResizable(false);Findpassword类:找回密码类package ;import java.awt.Color;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JTextField;public class findpassword extends JFrame JLabel nameLab2 = new JLabel(密保问题:你的学号是多少);JTextField name3 = new JTextField(20);Font fnt = new Font(Serief, Font.BOLD, 15);cell but = new cell(确定);public findpassword() this.setSize(500, 334);this.setLocation(300, 200);this.setVisible(true);this.setLayout(null);nameLab2.setFont(fnt);nameLab2.setForeground(Color.green);nameLab2.setBounds(140, 150, 200, 30);name3.setBounds(140, 180, 100, 30);this.add(name3);this.add(nameLab2);but.setBounds(160, 240, 147, 30);but.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) Statement st = null;ResultSet rs = null;boolean t = false;Connection con = null;String sql = SELECT name,mibao,password FROM qq;/查找语句try con = new JavaMysql().connnecton();st = con.createStatement();rs = st.executeQuery(sql); catch (ClassNotFoundException e2) / TODO Auto-generated catch blocke2.printStackTrace(); catch (SQLException e2) / TODO Auto-generated catch blocke2.printStackTrace();try while (rs.next() String qqmibao = rs.getString(mibao);String name1 = rs.getString(name);String password1 = rs.getString(password);if (name3.getText().equals(qqmibao)& name1.equals(JqqF.name.getText() /比较是否相等new lookpassword(password1);/如果和密保答案相等就输出t = true;break;if (t = false) new look2password(); catch (SQLException e1) / TODO Auto-generated catch blocke1.printStackTrace();try con.close();st.close();rs.close(); catch (SQLException e1) / TODO Auto-generated catch blocke1.printStackTrace(););this.add(but);Register类:注册新用户package ;import java.awt.Color;import java.awt.Font;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.SQLException;import java.sql.Statement;import javax.swing.ImageIcon;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;public class register extends JFrame implements MouseListener JTextField name1 = new JTextField(20);JLabel nameLab = new JLabel(输入新qq号:);JPasswordField nam = new JPasswordField(20);JLabel nameLa = new JLabel(输入qq密码:);JLabel nameLab2 = new JLabel(密保问题:你的学号是多少);JTextField name3 = new JTextField(20);Font fnt = new Font(Serief, Font.BOLD, 15);/ 背景图片cell but = new cell(确定);public register() super(注册);this.setSize(500, 334);this.setLocation(300, 200);this.setVisible(true);String path = pic/qq.png;/ 背景图片ImageIcon background = new ImageIcon(path);/ 把背景图片显示在一个标签里面JLabel label = new JLabel(background);label.setLayout(null);/ 把标签的大小位置设置为图片刚好填充整个面板label.setBounds(0, 0, this.getWidth(), this.getHeight();/ 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明JPanel imagePanel = (JPanel) this.getContentPane();imagePanel.setOpaque(false);nameLab.setFont(fnt);nameLab2.setFont(fnt);nameLab.setForeground(Color.yellow);nameLab2.setForeground(Color.green);nameLa.setFont(fnt);nameLa.setForeground(Color.yellow);nameLab.setBounds(140, 80, 100, 30);but.setBounds(160, 240, 147, 30);name1.setBounds(230, 80, 100, 30);nameLa.setBounds(140, 120, 100, 30);nam.setBounds(230, 120, 100, 30);nameLab2.setBounds(140, 150, 200, 30);name3.setBounds(140, 180, 100, 30);label.add(nameLab);label.add(but);label.add(nam);label.add(nameLa);label.add(nameLab2);label.add(name1);label.add(name3);but.addMouseListener(this);this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE);this.setResizable(false);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);public static void main(String args) register f = new register();Overridepublic void mouseClicked(MouseEvent e) String name = name1.getText();String mibao = name3.getText();String password = new String(nam.getPassword();PreparedStatement st = null;Connection con = null;String sql = INSERT INTO qq(name,mibao,password) VALUES(?,?,?);/预处理指令try con = new JavaMysql().connnecton();st = con.prepareStatement(sql); catch (ClassNotFoundException e2) / TODO Auto-generated catch blocke2.printStackTrace(); catch (SQLException e2) / TODO Auto-generated catch blocke2.printStackTrace();try st.setString(1, name);/向数据库输入账号st.setString(2, mibao);/密保答案st.setString(3, password);/向数据库输入密码st.executeUpdate();st.close();con.close(); catch (SQLException e1) / TODO Auto-generated catch blocke1.printStackTrace();JqqF.name.setText();JqqF.nam.setText();this.setVisible(false);Overridepublic void mousePressed(MouseEvent e) / TODO Auto-generated method stubOverridepublic void mouseReleased(MouseEvent e) / TODO Auto-generated method stubOverridepublic void mouseEntered(MouseEvent e) / TODO Auto-generated method stubOverridepublic void mouseExited(MouseEvent e) / TODO Auto-generated method stubJqqF2类:好友列表package ;import java.awt.event.WindowAdapter ;import java.awt.event.MouseListener ;import java.awt.event.WindowEvent ;import java.awt.event.MouseEvent ;import java.awt.Color ;import javax.swing.JFrame ;import java.awt.event.ActionListener ;import java.awt.event.WindowEvent ;import java.awt.event.ActionEvent ;import java.awt.Color ;import java.awt.Container;import java.awt.GridLayout ;import java.awt.Font ;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;import .Socket;import .UnknownHostException;import javax.swing.ImageIcon;import javax.swing.JFrame ;import javax.swing.JButton ;import javax.swing.JLabel ;import javax.swing.JSplitPane;import javax.swing.JTextArea ;import javax.swing.JPasswordField ;import javax.swing.JScrollPane ;import javax.swing.JPanel ;public class JqqF2 extends JFrame implements MouseListener String path4 = pic/m.png; / 背景图片 ImageIcon background4 = new ImageIcon(path4); cell bt = new cell(background4); public JqqF2()/ 准备好了一个面板super.setLayout(null) ;super.setTitle(qq好友列表) ;this.setSize(500, 334);this.setLocation(300, 200);this.setVisible(true); String path = pic/qq2.png; / 背景图片 ImageIcon background = new ImageIcon(path); / 把背景图片显示在一个标签里面 JLabel label = new JLabel(background); label.setLayout(null); / 把标签的大小位置设置为图片刚好填充整个面板 label.setBounds(0,0,300, 140); / 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明 JPanel imagePanel = (JPanel) this.getContentPane(); imagePanel.setOpaque(false); / 把背景图片添加到分层窗格的最底层作为背景 String path2 = pic/qq3.png; ImageIcon background2 = new ImageIcon(path2); / 把背景图片显示在一个标签里面 JLabel label2 = new JLabel(background2); label2.setLayout(null); label2.setBounds(5, 10, 88, 83); String path3 = pic/f.png; ImageIcon background3 = new ImageIcon(path3); / 把背景图片显示在一个标签里面 JLabel label3 = new JLabel(background3); label3.setLayout(null); label3.setBounds(0, 140, 324, 22); JLabel name = new JLabel(冰河世纪(); name.setForeground(Color.orange); name.setLayout(null); name.setBounds(97, 10, 180, 15); label.add(name); JLabel name2 = new JLabel(个性签名:坚持就是胜利); name2.setForeground(Color.GREEN); name2.setLayout(null); name2.setBounds(97, 60, 300, 15); label.add(name2); label.add(label2); this.add(label3);bt.addMouseListener(this);super.add(bt);bt.setBounds(0,162,325,60) ;this.setSize(300,550) ;this.setLocation(300,200) ;this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setResizable(false);Overridepublic void mouseClicked(MouseEvent e) JqqF3 f1 =null;/提升作用域try f1 = new JqqF3(吻柔哥();/初始化聊天窗口 catch (I
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 多跳自组网安全-洞察及研究
- 主题教育经验交流
- 绿色包装材料-洞察及研究
- 增强现实技术提升学习者沉浸度-洞察及研究
- 新疆维吾尔自治区阿勒泰地区福海县2025-2026学年八年级上学期9月月考数学试题(含答案)
- 山东省德州市2025-2026学年高三上学期九月月考联考历史试题(含答案)
- 知识产权法律服务合同样书5篇
- 关节置换微创器械开发-洞察及研究
- 学生见习安全培训课件
- 学生离校安全协议培训课件
- 浙江安保考试题库及答案
- 苏州安全生产教育培训课件
- 私密线上招商课件
- 兵团面试题目及答案
- 2025贵州贵阳市投资控股集团房地产置业有限公司招聘12人考试参考题库及答案解析
- 2025水发集团有限公司招聘216人考试模拟试题及答案解析
- 智慧加油站物联网综合管控平台建设综合解决方案
- 2025年甘肃省公职人员考试时事政治考试试题(附含答案)
- 花岗岩铺设方案
- 2025年护理疼痛试题及答案
- 桥梁工程监理工作实施方案
评论
0/150
提交评论