源代码 项目QQClientProject: LoguiGui 代码: package com.huaxia.qq.mzz.gui; import com.huaxia.qq.mzz.common.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...