您的位置:首页 > 编程语言 > Java开发

Q趣聊天通信软件应用设计

2017-07-06 15:33 162 查看
前言

防制的QQ聊天登录以及聊天功能,可以实现基本的注册账号,记住密码,密码找回,自动登录,注销等功能,多客户端实现无障碍聊天,传输文件,互不影响,使用简单方便。

Q趣聊天——客户端开发

话不多说,上图,界面是使用swing编写的,有点小丑,嘿嘿,可以导入一些包来修饰组件的,后期有时间就继续拓展。

聊天功能涉及到信息的传递,有关于socket网络编程,可以找些教材来看看,补一下这方面的基础。这里主要涉及到客户端跟服务器端两个方面的问题,在这里,我先讲的是客户端,从自己预定义功能出发,从界面表现层出发,然后业务逻辑层,最后DAO数据处理层。







开发——界面开发



给页面添加监听器,红色圈出了几个事件源,由点击它们出发事件,来跳到新页面或者执行查询,反馈提醒等功能。

- 登录

// 监听登陆按钮
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String u_name = u_nameField.getText(); // textField.getText();
if (file.length() != 0) {
if (userPro.containsKey(u_name)) {
String u_pwd = new String(passwordField.getPassword());
if (u_pwd.equals(userPro.getProperty(u_name))) {
try {
Socket client = new Socket("localhost", 8520);
loginButton.setEnabled(false);
//  clientLists frame = new clientLists(u_name, client);
CatChatroom frame = new CatChatroom(u_name, client);
frame.setVisible(true);// 显示聊天界面
setVisible(false);// 隐藏掉登陆界面
} catch (UnknownHostException e1) {
// TODO Auto-generated catch block
errorTip("The connection with the server is interrupted, please login again");
} catch (IOException e1) {
// TODO Auto-generated catch block
errorTip("The connection with the server is interrupted, please login again");
}

} else {
lblNewLabel_2.setText("*您输入的密码有误!");
passwordField.requestFocus();
}
} else {
lblNewLabel_3.setText("*您输入昵称不存在!");
u_nameField.setText("");
passwordField.setText("");
u_nameField.requestFocus();
}
} else {
lblNewLabel_3.setText("*请您输入昵称!");
u_nameField.setText("");
passwordField.setText("");
u_nameField.requestFocus();
}
}
});


注册

// 注册按钮监听
lblNewLabel.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
reginFrame frame = new reginFrame();
frame.setVisible(true);// 显示注册界面

}


记住密码

//记住密码监视器
class CheckListen implements ItemListener {
public void itemStateChanged(ItemEvent envent) {
Properties userPro = new Properties();
File file = new File("Users.properties");
CatUtil.loadPro(userPro, file);
if (chckbxNewCheckBox.isSelected()) {
String u_name = u_nameField.getText();
//      passwordField.setText(userPro.getProperty(u_name));
userPro.setProperty("flag", "1");
} else {
userPro.setProperty("flag", "0");
}
try {
userPro.store(new FileOutputStream(file), "Infor
4000
mation of regin");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}


找回密码

// 找回密码按钮监听
lblNewLabel_1.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
// lblNewLabel_1.setEnabled(false);
findPassword frame = new findPassword();
frame.setVisible(true);// 显示注册界面
// setVisible(false);// 隐藏掉登陆界面

}


源码下载地址:

http://download.csdn.net/download/u011958281/9930368
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java 聊天 swing 界面 密码
相关文章推荐