java在线聊天项目 客户端登陆窗口LoginDialog的注册用户功能 修改注册逻辑 增空用户名密码的反馈 增加showMessageDialog()提示框
LoginDialog类的代码修改如下:
package com.swift.frame; import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ConnectException;
import java.net.Socket;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException; import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.TitledBorder; import com.swift.jdbc.DBAdd;
import com.swift.jdbc.DBUtil;
import com.swift.jdbc.User;
import com.swift.util.Center; public class LoginDialog extends JDialog { private JPasswordField passwordField_2;
private JPasswordField passwordField_1;
private JTextField textField_2;
private JTextField textField; Socket s;
DataOutputStream dos;
DataInputStream dis; public static void main(String args[]) {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true); try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
} EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LoginDialog dialog = new LoginDialog();
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} public LoginDialog() {
super();
setResizable(false);
setTitle("在线聊天登录框");
getContentPane().setLayout(null);
setBounds(100, 100, 427, 301);// 注册时高度为578,不注册是301 // 设置窗口居中
this.setLocation(Center.getPoint(this.getSize())); final JButton button_1 = new JButton();
button_1.setText("登录");
button_1.setBounds(230, 222, 106, 36);
getContentPane().add(button_1); final JTextField textField_1 = new JTextField();
textField_1.setBounds(148, 90, 192, 42);
getContentPane().add(textField_1); final JLabel label = new JLabel();
label.setText("帐 号");
label.setBounds(76, 102, 66, 18);
getContentPane().add(label); final JLabel label_1 = new JLabel();
label_1.setText("密 码");
label_1.setBounds(76, 167, 66, 18);
getContentPane().add(label_1); final JPasswordField passwordField = new JPasswordField();
passwordField.setBounds(148, 155, 192, 42);
getContentPane().add(passwordField); final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
if (LoginDialog.this.getHeight() == 301) {
LoginDialog.this.setSize(427, 578);
} else {
LoginDialog.this.setSize(427, 301);
}
// 设置窗口不断居中
LoginDialog.this.setLocation(Center.getPoint(LoginDialog.this.getSize()));
}
});
button.setText("注册");
button.setBounds(76, 222, 106, 36);
getContentPane().add(button); final JPanel panel = new JPanel();
panel.setLayout(null);
panel.setBorder(new TitledBorder(null, "注册用户", TitledBorder.DEFAULT_JUSTIFICATION,
TitledBorder.DEFAULT_POSITION, null, null));
panel.setBounds(10, 278, 401, 226);
getContentPane().add(panel); final JLabel label_2 = new JLabel();
label_2.setBounds(44, 41, 65, 18);
label_2.setText("手机号:");
panel.add(label_2); textField = new JTextField();
textField.setBounds(115, 35, 225, 30);
panel.add(textField); final JButton button_2 = new JButton();
button_2.setText("发送验证");
button_2.setBounds(243, 75, 97, 30);
panel.add(button_2); textField_2 = new JTextField();
textField_2.setBounds(115, 104, 95, 30);
panel.add(textField_2); final JLabel label_3 = new JLabel();
label_3.setText("验证码:");
label_3.setBounds(44, 110, 65, 18);
panel.add(label_3); passwordField_1 = new JPasswordField();
passwordField_1.setBounds(115, 143, 231, 30);
panel.add(passwordField_1); passwordField_2 = new JPasswordField();
passwordField_2.setBounds(115, 175, 231, 30);
panel.add(passwordField_2); final JLabel label_4 = new JLabel();
label_4.setText("密 码:");
label_4.setBounds(44, 149, 65, 18);
panel.add(label_4); final JLabel label_5 = new JLabel();
label_5.setText("验证密码:");
label_5.setBounds(44, 181, 65, 18);
panel.add(label_5); final JButton button_3 = new JButton();
button_3.setBounds(47, 510, 97, 30);
getContentPane().add(button_3);
button_3.setText("放弃"); final JButton button_4 = new JButton();
button_4.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) { String phone = textField.getText();
String password = null;
String str1 = new String(passwordField_1.getPassword()).trim();
String str2 = new String(passwordField_2.getPassword()).trim();
if (!phone.equals("") && !str1.equals("") && !str2.equals("")) {
if (str1.equals(str2)) {
password = new String(passwordField_2.getPassword()).trim();
try {
dos.writeUTF(phone);
dos.writeUTF(password);
} catch (IOException e1) {
e1.printStackTrace();
}
} else {
javax.swing.JOptionPane.showMessageDialog(LoginDialog.this, "输入密码不一致...");
System.out.println("输入密码不一致...");
passwordField_1.setText("");
passwordField_2.setText("");
} }else {
javax.swing.JOptionPane.showMessageDialog(LoginDialog.this, "用户名密码必须填写...");
return;
}
}
}); button_4.setBounds(262, 510, 97, 30);
getContentPane().add(button_4);
button_4.setText("注册用户"); connect();
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
disconnect();
}
});
} public void connect() {
try {
s = new Socket("127.0.0.1", 8888);
System.out.println("一个客户端登陆中....!");
dos = new DataOutputStream(s.getOutputStream());
dis = new DataInputStream(s.getInputStream()); } catch (ConnectException e) {
System.out.println("服务端异常.........");
System.out.println("请确认服务端是否开启.........");
} catch (IOException e) {
e.printStackTrace();
}
} public void disconnect() {
try {
if (dos != null)
dos.close();
if (s != null)
s.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
java在线聊天项目 客户端登陆窗口LoginDialog的注册用户功能 修改注册逻辑 增空用户名密码的反馈 增加showMessageDialog()提示框的更多相关文章
- java在线聊天项目 swt可视化窗口Design 登录框注册按钮点击改变窗口大小——出现注册面板 实现打开登录框时屏幕居中
登录框注册按钮点击改变窗口大小——出现注册面板 首先用swt可视化设计登录窗口如下图: 此时窗口高度为578 没点击注册时高度为301(可自己定) 注意:注册用户的Jpanel 的border选择T ...
- java在线聊天项目 swt可视化窗口Design 重新设计好友列表窗口 增加菜单栏
增加的菜单栏效果图如下: eclipse 中调整到 swt的design视图下 控件区域选择Menu Controls 将Menu Bar拖动到窗口标题栏 将Cascaded Menu拖动到Menu ...
- java在线聊天项目 swt可视化窗口Design 好友列表窗口
熟练使用各种布局方式 FlowLayout 流布局 left center right等 BorderLayout 边框布局 east west sorth north center Absolute ...
- java在线聊天项目 swt可视化窗口Design 重新设计聊天窗口
设计的聊天窗口如下: 制作过程: 首先,在默认的BorderLayout视图下, 上边也就是North处添加一个JPanel,将Layout调整为BorderLayout,West放一个JLabel用 ...
- java在线聊天项目1.2版 ——开启多个客户端,分别实现数据库注册和登录功能后,成功登陆则登录框消失,好友列表窗出现
登录框消失语句 dispose(); 好友列表窗出现 使用new FriendsFrame(phone,s); 登陆对话框代码修改如下: package com.swift.frame; import ...
- java在线聊天项目0.1版本 制作客户端窗体,使用swing(用户界面开发工具包)和awt(抽象窗口工具包)
建立Chat项目,并在项目中创建窗口类 package com.swift; import java.awt.BorderLayout; import javax.swing.JFrame; impo ...
- java在线聊天项目1.1版 ——开启多个客户端,分别实现注册和登录功能,使用客户端与服务端信息request机制,重构线程,将单独的登录和注册线程合并
实现效果图: eclipse项目中初步整合之前的各个客户端和服务端的窗口与工具类,效果如下图: 已将注册服务器线程RegServer功能放到LoginServer中,使用客户端与服务端的request ...
- java在线聊天项目1.3版 ——设计好友列表框功能
设计好友列表框功能,思路—— 1.当客户端成功登陆后,则客户端把成功登陆信息发送给服务端, 2.由服务端将接收到来自各个成功登陆的客户端的用户信息添加进好友列表, 3.每当有成功登陆的用户就向各个客户 ...
- java在线聊天项目 实现基本聊天功能后补充的其他功能详细需求分析 及所需要掌握的Java知识基础 SWT的激活方法,swt开发包下载,及破解激活码
补充聊天项目功能,做如下需求分析: 梳理项目开发所需的必要Java知识基础 GUI将使用更快速的swt实现 SWT(Standard Widget Toolkit) Standard Widget T ...
随机推荐
- 阿里mavne中央仓库
https://www.cnblogs.com/ae6623/p/4416256.html 待整理
- 用shell脚本监控MySQL主从同步
企业面试题1:(生产实战案例):监控MySQL主从同步是否异常,如果异常,则发送短信或者邮件给管理员.提示:如果没主从同步环境,可以用下面文本放到文件里读取来模拟:阶段1:开发一个守护进程脚本每30秒 ...
- C - Aladdin and the Flying Carpet
#include<bitset> #include<map> #include<vector> #include<cstdio> #include< ...
- excel输入值非法,限定了可以输入的数值怎么办
回到excel的编辑界面,点击工具栏的“数据”标签,如图所示. 继续在“数据”标签的下面找到“数据验证”或“数据有效性”的按钮,点击该选项,然后继续下一步. 在弹出的选择框中选择“数据验证”选项,如图 ...
- [題解]hdu_6412公共子序列
https://blog.csdn.net/nka_kun/article/details/81902421 #include<bits/stdc++.h> #define ll long ...
- numpy使用示例
numpy介绍 创建numpy的数 一维数组是什么样子 可以理解为格子纸的一行就是一个一维数据 two_arr = np.array([1, 2, 3]) 二维数组什么样子 理解为一张格子纸, 多个一 ...
- Codeforces Round #541 (Div. 2) A.Sea Battle
链接:https://codeforces.com/contest/1131/problem/A 题意: 给两个矩形,一个再上一个在下,求两个矩形合并的周围一圈的面积. 思路: 因为存在下面矩形宽度大 ...
- bryce1010专题训练——CDQ分治
Bryce1010模板 CDQ分治 1.与普通分治的区别 普通分治中,每一个子问题只解决它本身(可以说是封闭的) 分治中,对于划分出来的两个子问题,前一个子问题用来解决后一个子问题而不是它本身 2.试 ...
- Codeforces Round #388 (Div. 2) D
There are n people taking part in auction today. The rules of auction are classical. There were n bi ...
- 洛谷P2514||bzoj2426 [HAOI2010]工厂选址
洛谷P2514 bzoj2426 其实是个简单的贪心,然而不适合在脑子不清醒的时候做...看不懂题意续了1个小时 很容易发现应该枚举新建哪个发电厂,对于这种方案就是取其中b吨煤运到原来发电厂,取剩下( ...