java聊天工具源代码

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

源代码

项目QQClientProject:

LoguiGui代码:

package com.huaxia.qq.mzz.gui;

import mon.Message;

import mon.MessageService;

import er;

import .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, "异常提示", RMA TION_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);

}

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new LoguiGui().setVisible(true);

}

});

}

RegiterGui代码:

package com.huaxia.qq.mzz.gui;

import mon.Message; import mon.MessageService; import er;

import .Socket;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.util.Arrays;

import javax.swing.JOptionPane;

public class RegiterGui extends javax.swing.JDialog { private static final String url = "jdbc:odbc:mydata"; private static final String user = "mzz";

private static final String pwd = "mzz";

public Socket connectServer() {

Socket s = null;

try {

s = new Socket("127.0.0.1", 6666);

} catch (Exception e) {

e.printStackTrace();

}

return s;

相关文档
最新文档