java聊天工具源代码.docVIP

  • 2
  • 0
  • 约1.92万字
  • 约 23页
  • 2020-08-01 发布于上海
  • 举报
源代码 项目QQClientProject: LoguiGui代码: package com.huaxia.qq.mzz.gui; import com.huaxia.qq.mon.Message; import com.huaxia.qq.mzz.common.MessageService; import com.huaxia.qq.mzz.common.User; import java.net.Socket; import javax.swing.JOptionPane; public class LoguiGui extends javax.swing.JFrame { public LoguiGui() { initComponents(); } public Socket connectServer() { Socket s = null; try { s = new Socket("127.0.0.1, 6666); } catch (Exception e) { e.printStackTrace(); } return s; } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: String name = nameItem.getText(); System.out.println(用户名: + name); if (name == null || .equals(name)) { JOptionPane.showMessageDialog(this, 用户名不能为空,请输入, 异常提示, JOptionPane.ERROR_MESSAGE); return; } String pwd = new String(pwdItem.getPassword()); System.out.println("密码: + pwd); if (pwd.length() == 0) { JOptionPane.showMessageDialog(this, 密码不能为空,请输入, 异常提示, JOptionPane.ERROR_MESSAGE); return; } final Socket s = this.connectServer(); //构造消息 final User u = new User(name, pwd); Message msg = new Message(1, u); //执行发送 MessageService.getInstance().sendMsg(msg, s); //接受消息【接收注册结果】 Message result = MessageService.getInstance().receiveMsg(s); // 取出注册成功的标志 String r = (String) result.getBody(); if (r == null) {//注册成功 java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ChatGui(u, s).setVisible(true); } }); this.dispose(); } else { JOptionPane.showMessageDialog(this, "登录失败:" + r, 异常提示, JOptionPane.INFORMATION_MESSAGE); } private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) { //     TODO add your handling code here: final LoguiGui gui = this; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { RegiterGui dialog = new RegiterGui(gui, true); dialog.setLocationRelativeTo(gui); dialog.setVisible(true); } }); } private void jButton2MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: nameItem.setText(null); pwdItem.setText(null);

文档评论(0)

1亿VIP精品文档

相关文档