diff --git a/src/UserLogin-master/UserLogin-master/.classpath b/src/UserLogin-master/UserLogin-master/.classpath
new file mode 100644
index 0000000..d634cfc
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/src/UserLogin-master/UserLogin-master/.idea/.gitignore b/src/UserLogin-master/UserLogin-master/.idea/.gitignore
new file mode 100644
index 0000000..50d9d22
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/.idea/.gitignore
@@ -0,0 +1,3 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
diff --git a/src/UserLogin-master/UserLogin-master/.idea/libraries/jdbc.xml b/src/UserLogin-master/UserLogin-master/.idea/libraries/jdbc.xml
new file mode 100644
index 0000000..82451b5
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/.idea/libraries/jdbc.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/.idea/misc.xml b/src/UserLogin-master/UserLogin-master/.idea/misc.xml
new file mode 100644
index 0000000..53c6aae
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/.idea/modules.xml b/src/UserLogin-master/UserLogin-master/.idea/modules.xml
new file mode 100644
index 0000000..aab8690
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/.project b/src/UserLogin-master/UserLogin-master/.project
new file mode 100644
index 0000000..3cdb6a9
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/.project
@@ -0,0 +1,17 @@
+
+
+ UserLogin-master
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/src/UserLogin-master/UserLogin-master/README.md b/src/UserLogin-master/UserLogin-master/README.md
new file mode 100644
index 0000000..296d6e9
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/README.md
@@ -0,0 +1,2 @@
+Java--用户登录界面(连接Mysql数据库)
+![输入图片说明](https://images.gitee.com/uploads/images/2022/0413/184214_a8326845_9840785.png "未标题-1.png")
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/User/.idea/.gitignore b/src/UserLogin-master/UserLogin-master/User/.idea/.gitignore
new file mode 100644
index 0000000..50d9d22
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/User/.idea/.gitignore
@@ -0,0 +1,3 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
diff --git a/src/UserLogin-master/UserLogin-master/User/.idea/misc.xml b/src/UserLogin-master/UserLogin-master/User/.idea/misc.xml
new file mode 100644
index 0000000..b09fb27
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/User/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/User/.idea/modules.xml b/src/UserLogin-master/UserLogin-master/User/.idea/modules.xml
new file mode 100644
index 0000000..ca153bb
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/User/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/User/Login.java b/src/UserLogin-master/UserLogin-master/User/Login.java
new file mode 100644
index 0000000..30ee9a2
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/User/Login.java
@@ -0,0 +1,40 @@
+package com.weh.User;
+
+//登录所需要的数据转入
+public class Login {
+ String id;
+ String password;
+ LoginDemo loginDemo;
+ boolean loginSuccess = false;
+
+ public LoginDemo getLoginDemo() {
+ return loginDemo;
+ }
+ public void setLoginDemo(LoginDemo loginDemo) {
+ this.loginDemo = loginDemo;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public boolean isLoginSuccess() {
+ return loginSuccess;
+ }
+
+ public void setLoginSuccess(boolean loginSuccess) {
+ this.loginSuccess = loginSuccess;
+ }
+}
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/User/LoginDemo.java b/src/UserLogin-master/UserLogin-master/User/LoginDemo.java
new file mode 100644
index 0000000..f2dff31
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/User/LoginDemo.java
@@ -0,0 +1,166 @@
+package com.weh.User;
+
+import javax.swing.*;
+import javax.swing.plaf.basic.BasicButtonUI;
+import javax.swing.plaf.basic.BasicPanelUI;
+import java.awt.*;
+import java.sql.SQLException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/*
+* 登录窗口
+*/
+public class LoginDemo extends JFrame {
+ public LoginDemo() {
+ super("HI登录界面");
+ //获取显示屏的大小
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ int sw = screenSize.width;
+ int sh = screenSize.height;
+ //窗口宽高大小
+ int width = 500;
+ int height = 340;
+ this.setBounds((sw - width) / 2, (sh - height) / 2, width, height);//设置窗口的位置
+ this.setIconImage(Toolkit.getDefaultToolkit().getImage(LoginDemo.class.getResource("/com/weh/img/chatping.jpg")));//窗口图标
+ ImageIcon background = new ImageIcon(LoginDemo.class.getResource("/com/weh/img/chat.jpg")); //背景图片
+ JLabel label = new JLabel(background); // 把背景图片显示在一个标签里面
+ label.setBounds(0, 0, this.getWidth(), this.getHeight()); // 把标签的大小位置设置为图片刚好填充整个面板
+ JPanel imagePanel = (JPanel) this.getContentPane(); // 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明
+ imagePanel.setOpaque(false); // 窗口透明
+ this.getLayeredPane().add(label, Integer.valueOf(Integer.MIN_VALUE)); // 把背景图片添加到分层窗格的最底层作为背景
+
+ JPanel panel = new JPanel();
+ //盒子模块
+ Box ubox = Box.createHorizontalBox();
+ Box pbox = Box.createHorizontalBox();
+ Box vbox = Box.createVerticalBox();
+
+ //创建界面工具类
+ JLabel uLabel = new JLabel(" HI :"); //文本设计
+ uLabel.setFont(new Font("微软雅黑", Font.BOLD, 15));
+ uLabel.setForeground(new Color(0xFBFCFD)); // 设置前景色
+ JTextField uField = new JTextField(); //输入框
+ uField.setFont(new Font("Arial", Font.BOLD, 15));
+ uField.setToolTipText("HI");// 悬停显示
+ uField.setColumns(12);
+
+ JLabel pLabel = new JLabel("密 码:"); //文本设计
+ pLabel.setFont(new Font("微软雅黑", Font.BOLD, 15));
+ pLabel.setForeground(new Color(0xFBFCFD)); // 设置前景色
+ JPasswordField pFd = new JPasswordField();
+ pFd.setFont(new Font("Arial", Font.BOLD, 15));
+ pFd.setToolTipText("密码");// 悬停显示
+ pFd.setColumns(12);
+ // 如果使用其他回显字符,可以设置大小,但是星星不可以。。。
+ pFd.setEchoChar('●');// 星星符号
+
+ JButton button1 = new JButton("登录"); //登录按钮
+ button1.setToolTipText("登录");// 悬停显示
+ JButton button2 = new JButton("重置"); //重置按钮
+ button2.setToolTipText("重置");// 悬停显示
+ JMenu Menubutton3 = new JMenu("注册账号"); //重置按钮
+ Menubutton3.setToolTipText("注册账号");// 悬停显示
+ // 字体设置
+ button1.setFont(new Font("微软雅黑", Font.BOLD, 18));
+ button1.setForeground(Color.white); // 设置前景色
+ button1.setBackground(new Color(0x08BDFD));
+ button1.setDefaultCapable(true);
+ button1.setBounds((this.getWidth() - 120 - 180) / 2, 250, 120, 30); // 设置按钮位置,及按钮大小
+ button1.setCursor(new Cursor(Cursor.HAND_CURSOR)); //鼠标手势的设置
+
+ button2.setFont(new Font("微软雅黑", Font.BOLD, 18));
+ button2.setForeground(Color.white); // 设置前景色
+ button2.setBackground(new Color(0x08BDFD));
+ button2.setDefaultCapable(true);
+ button2.setCursor(new Cursor(Cursor.HAND_CURSOR));//鼠标手势的设置
+ button2.setBounds((this.getWidth() - 120 + 180) / 2, 250, 120, 30); // 设置按钮位置,及按钮大小
+
+ Menubutton3.setFont(new Font("微软雅黑", Font.BOLD, 12));
+ Menubutton3.setForeground(new Color(0x02FCFC)); // 设置前景色
+ Menubutton3.setUI(new BasicButtonUI()); //恢复基本视觉效果
+ Menubutton3.setBounds(5, 280, 85, 20); // 设置按钮位置,及按钮大小
+ Menubutton3.setContentAreaFilled(false); // 设置按钮透明
+ Menubutton3.setCursor(new Cursor(Cursor.HAND_CURSOR));
+
+ /*
+ 分区模块布局
+ */
+ //小盒子,设计用户名布局模块
+ ubox.add(uLabel);
+ ubox.add(Box.createHorizontalStrut(5));//插入中间盒子宽度为5,作为相邻文本的空隙
+ ubox.add(uField);
+ //小盒子,设计密码框布局模块
+ pbox.add(pLabel);
+ pbox.add(Box.createHorizontalStrut(5));//插入中间盒子宽度为5,作为相邻文本的空隙
+ pbox.add(pFd);
+
+ //大盒子
+ vbox.add(Box.createVerticalStrut(80));//插入中间盒子高度为80,作为上下文本的空隙
+ vbox.add(ubox);
+ vbox.add(Box.createVerticalStrut(60));//插入中间盒子高度为60,作为上下文本的空隙
+ vbox.add(pbox);
+
+
+ uField.setText("3037502828"); //设置默认账号
+ pFd.setText("123456"); //设置默认密码
+ panel.setUI(new BasicPanelUI()); //恢复基本视觉效果
+ panel.setOpaque(false); // 面板透明
+ panel.add(vbox, BorderLayout.CENTER);//vbox盒子居中
+ this.setDefaultCloseOperation(EXIT_ON_CLOSE);
+ this.add(button1);
+ this.add(button2);
+ this.add(Menubutton3);
+ this.add(panel);
+ this.setVisible(true);
+ this.setResizable(false);
+
+ //点击按钮的监听事件
+ button1.addActionListener(e -> { //登录按钮监听事件
+ try {
+ //正则法则,验证输入数据的字符是否都是数字
+ String HI =uField.getText().trim();
+ String regex = "^\\d+$";
+ Pattern p =Pattern.compile(regex);
+ Matcher m = p.matcher(HI);
+ if(m.matches()){//匹配成功,则传入输入的数据
+ init(this,uField, pFd);
+ }else {
+ JOptionPane.showMessageDialog(null, "只能输入数字,请正确输入!", "警告", JOptionPane.WARNING_MESSAGE);
+ }
+ } catch (Exception exception) {
+ JOptionPane.showMessageDialog(null, "异常", "警告", JOptionPane.WARNING_MESSAGE);
+ }
+ });
+ button2.addActionListener(e -> {//重置按钮监听事件
+ uField.setText("");
+ pFd.setText("");
+ });
+ Menubutton3.addActionListener(e -> {//跳转到注册窗口按钮监听事件
+ try {
+ this.dispose();
+ Thread.sleep(1000);
+ new RegisterDemo();
+ } catch (InterruptedException interruptedException) {
+ JOptionPane.showMessageDialog(null, "异常", "警告", JOptionPane.WARNING_MESSAGE);
+ }
+ });
+ }
+
+ public void init(LoginDemo loginDemo,JTextField uField, JPasswordField pFd) {
+ Login login;
+ UserLogin UserLogin;
+ try {
+ login=new Login();
+ login.setLoginDemo(loginDemo);
+ login.setId(uField.getText());
+ char[] p = pFd.getPassword();
+ login.setPassword(new String(p));
+ UserLogin = new UserLogin();
+ UserLogin.readLogin(login);
+ } catch (SQLException | ClassNotFoundException e) {
+ JOptionPane.showMessageDialog(null, "异常", "警告", JOptionPane.WARNING_MESSAGE);
+ }
+
+ }
+}
diff --git a/src/UserLogin-master/UserLogin-master/User/Register.java b/src/UserLogin-master/UserLogin-master/User/Register.java
new file mode 100644
index 0000000..bd75a25
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/User/Register.java
@@ -0,0 +1,30 @@
+package com.weh.User;
+
+//注册所需要的数据转入
+public class Register {
+ String name;
+ String id;
+ String password;
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
+
diff --git a/src/UserLogin-master/UserLogin-master/User/RegisterDemo.java b/src/UserLogin-master/UserLogin-master/User/RegisterDemo.java
new file mode 100644
index 0000000..bb26c8a
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/User/RegisterDemo.java
@@ -0,0 +1,223 @@
+package com.weh.User;
+
+import javax.swing.*;
+import javax.swing.plaf.basic.BasicButtonUI;
+import javax.swing.plaf.basic.BasicPanelUI;
+import java.awt.*;
+import java.sql.SQLException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/*
+ * 注册窗口
+ */
+public class RegisterDemo extends JFrame {
+ public RegisterDemo() {
+ //获取显示屏的大小
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ int sw = screenSize.width;
+ int sh = screenSize.height;
+ this.setTitle("HI注册界面");
+ int width = 500;
+ int height = 600;
+ this.setBounds((sw - width) / 2, (sh - height) / 2, width, height);// 设置窗口的位置
+ this.setIconImage(Toolkit.getDefaultToolkit().getImage(RegisterDemo.class.getResource("/com/weh/img/chatping.jpg")));// 图标
+ ImageIcon background = new ImageIcon(RegisterDemo.class.getResource("/com/weh/img/chat.gif")); // 背景图片
+ JLabel label = new JLabel(background); // 把背景图片显示在一个标签里面
+ label.setBounds(0, 0, this.getWidth(), this.getHeight()); // 把标签的大小位置设置为图片刚好填充整个面板
+ JPanel imagePanel = (JPanel) this.getContentPane(); // 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明
+ imagePanel.setOpaque(false); // 窗口透明
+ this.getLayeredPane().add(label, Integer.valueOf(Integer.MIN_VALUE)); // 把背景图片添加到分层窗格的最底层作为背景
+
+ //盒子模块
+ Box namebox = Box.createHorizontalBox();
+ Box ubox = Box.createHorizontalBox();
+ Box pbox = Box.createHorizontalBox();
+ Box repbox = Box.createHorizontalBox();
+ Box vbox = Box.createVerticalBox();
+
+ JLabel nameLabel = new JLabel("用户名 :"); //文本设计
+ nameLabel.setFont(new Font("微软雅黑", Font.BOLD, 13));
+ nameLabel.setForeground(new Color(0x02FFFF)); // 设置前景色
+ JTextField nameField = new JTextField(); //输入框
+ nameField.setFont(new Font("黑体", Font.BOLD, 15));
+ nameField.setToolTipText("用户名");
+ nameField.setColumns(15);
+
+
+ JLabel uLabel = new JLabel(" HI :"); //文本设计
+ uLabel.setFont(new Font("微软雅黑", Font.BOLD, 13));
+ uLabel.setForeground(new Color(0x02FFFF)); // 设置前景色
+ JTextField uField = new JTextField(); //输入框
+ uField.setFont(new Font("Arial", Font.BOLD, 15));
+ uField.setToolTipText("HI");
+ uField.setColumns(15);
+
+ JLabel pLabel = new JLabel("密 码 :"); //文本设计
+ pLabel.setFont(new Font("微软雅黑", Font.BOLD, 13));
+ pLabel.setForeground(new Color(0x02FFFF)); // 设置前景色
+ JPasswordField pFd = new JPasswordField();
+ pFd.setFont(new Font("Arial", Font.BOLD, 15));
+ pFd.setToolTipText("密码");// 悬停显示
+ pFd.setColumns(15);
+ // 如果使用其他回显字符,可以设置大小,但是星星不可以。。。
+ pFd.setEchoChar('●');// 星星符号
+
+
+ JLabel RepLabel = new JLabel("确认密码:"); //文本设计
+ RepLabel.setFont(new Font("微软雅黑", Font.BOLD, 13));
+ RepLabel.setForeground(new Color(0x02FFFF)); // 设置前景色
+ JPasswordField RepFd = new JPasswordField();
+ RepFd.setFont(new Font("Arial", Font.BOLD, 15));
+ RepFd.setToolTipText("确认密码");// 悬停显示
+ RepFd.setColumns(15);
+ // 如果使用其他回显字符,可以设置大小,但是星星不可以。。。
+ RepFd.setEchoChar('●');// 星星符号
+
+ JButton button1 = new JButton("注册"); //登录按钮
+ button1.setToolTipText("注册");// 悬停显示
+ JButton button2 = new JButton("重置"); //重置按钮
+ button2.setToolTipText("重置");// 悬停显示
+ JMenu Menubutton3 = new JMenu("返回登录"); //重置按钮
+ Menubutton3.setToolTipText("返回登录");// 悬停显示
+
+ button1.setFont(new Font("微软雅黑", Font.BOLD, 18));
+ button1.setForeground(Color.white); // 设置前景色
+ button1.setBackground(new Color(0x08BDFD));
+ button1.setDefaultCapable(true);
+ button1.setBounds((this.getWidth() - 120 - 180) / 2, this.getHeight() - 150, 120, 30); // 设置按钮位置,及按钮大小
+ button1.setCursor(new Cursor(Cursor.HAND_CURSOR)); //鼠标手势的设置
+
+ button2.setFont(new Font("微软雅黑", Font.BOLD, 18));
+ button2.setForeground(Color.white); // 设置前景色
+ button2.setBackground(new Color(0x08BDFD));
+ button2.setDefaultCapable(true);
+ button2.setCursor(new Cursor(Cursor.HAND_CURSOR));//鼠标手势的设置
+ button2.setBounds((this.getWidth() - 120 + 180) / 2, this.getHeight() - 150, 120, 30); // 设置按钮位置,及按钮大小
+
+ Menubutton3.setFont(new Font("微软雅黑", Font.BOLD, 12));
+ Menubutton3.setForeground(Color.white); // 设置前景色
+ Menubutton3.setBackground(new Color(0x08BDFD));
+ Menubutton3.setUI(new BasicButtonUI()); //恢复基本视觉效果
+ Menubutton3.setBounds(5, this.getHeight() - 70, 85, 20); // 设置按钮位置,及按钮大小
+ Menubutton3.setContentAreaFilled(false); // 设置按钮透明
+ Menubutton3.setCursor(new Cursor(Cursor.HAND_CURSOR));
+
+ /*
+ 分区模块布局
+ */
+
+ //小盒子,设计用户名模块
+ namebox.add(nameLabel);
+ namebox.add(Box.createHorizontalStrut(5));//插入中间盒子宽度为5,作为相邻文本的空隙
+ namebox.add(nameField);
+
+ ubox.add(uLabel);
+ ubox.add(Box.createHorizontalStrut(5));//插入中间盒子宽度为5,作为相邻文本的空隙
+ ubox.add(uField);
+ //小盒子,设计密码模块
+ pbox.add(pLabel);
+ pbox.add(Box.createHorizontalStrut(5));
+ pbox.add(pFd);
+
+ repbox.add(RepLabel);
+ repbox.add(Box.createHorizontalStrut(5));
+ repbox.add(RepFd);
+
+ vbox.add(Box.createVerticalStrut(90));//插入中间盒子高度为90,作为上下文本的空隙
+ vbox.add(namebox);
+ vbox.add(Box.createVerticalStrut(65));
+ vbox.add(ubox);
+ vbox.add(Box.createVerticalStrut(65));
+ vbox.add(pbox);
+ vbox.add(Box.createVerticalStrut(65));
+ vbox.add(repbox);
+
+
+ JPanel panel = new JPanel();
+ panel.setUI(new BasicPanelUI()); //恢复基本视觉效果
+ panel.setOpaque(false); // 面板透明
+ panel.add(vbox, BorderLayout.CENTER);
+ this.setDefaultCloseOperation(EXIT_ON_CLOSE);
+ this.add(button1);
+ this.add(button2);
+ this.add(Menubutton3);
+ this.add(panel);
+ this.setVisible(true);
+ this.setResizable(false);
+
+ //注册按钮监听
+ button1.addActionListener(e -> {
+ String pField = new String(pFd.getPassword());//转换
+ String repField = new String(RepFd.getPassword());//转换
+ try {
+ if (nameField.getText().isEmpty() || pField.isEmpty() || repField.isEmpty()||uField.getText().isEmpty()) {
+ if (nameField.getText().isEmpty()) {
+ JOptionPane.showMessageDialog(null, "用户名不能为空", "提示", JOptionPane.WARNING_MESSAGE);
+ } else if(uField.getText().isEmpty()){
+ JOptionPane.showMessageDialog(null, "HI号不能为空", "提示", JOptionPane.WARNING_MESSAGE);
+ }
+ else if (pField.isEmpty()) {
+ JOptionPane.showMessageDialog(null, "密码不能为空", "提示", JOptionPane.WARNING_MESSAGE);
+ } else {
+ JOptionPane.showMessageDialog(null, "确认密码不能为空", "提示", JOptionPane.WARNING_MESSAGE);
+ }
+ } else {
+ if (!pField.equals(repField)) {
+ JOptionPane.showMessageDialog(null, "两次密码不一致", "提示", JOptionPane.WARNING_MESSAGE);
+ } else {
+ String HI =uField.getText().trim();
+ String regex = "^\\d+$";
+ Pattern p =Pattern.compile(regex);
+ Matcher m = p.matcher(HI);
+ if(m.matches()){
+ init(nameField,uField, pFd);
+ }else{
+ JOptionPane.showMessageDialog(null, "HI号只能输入数字,请正确输入!", "警告", JOptionPane.WARNING_MESSAGE);
+ }
+ }
+ }
+ } catch (Exception exception) {
+ JOptionPane.showMessageDialog(null, "异常", "警告", JOptionPane.WARNING_MESSAGE);
+ }
+ });
+
+ //重置按钮监听
+ button2.addActionListener(e -> {
+ nameField.setText(null);
+ uField.setText(null);
+ pFd.setText(null);
+ RepFd.setText(null);
+ });
+
+ //返回登录窗口按钮监听
+ Menubutton3.addActionListener(e -> {
+ try {
+ this.dispose();
+ Thread.sleep(1000);
+ new LoginDemo();
+ } catch (Exception exception) {
+ JOptionPane.showMessageDialog(null, "异常", "警告", JOptionPane.WARNING_MESSAGE);
+ }
+ });
+ }
+
+ public void init(JTextField nameField,JTextField uField, JPasswordField pFd) {
+ Register register;
+ UserRegister userRegister;
+ try {
+ register = new Register();
+ register.setName(nameField.getText());
+ register.setId(uField.getText());
+ char[] p1 = pFd.getPassword();
+ register.setPassword(new String(p1));
+ userRegister = new UserRegister();
+ userRegister.writeRegister(register);
+ uField.setText(null);
+ nameField.setText(null);
+ } catch (SQLException e) {
+ JOptionPane.showMessageDialog(null, "异常", "警告", JOptionPane.WARNING_MESSAGE);
+ }
+ }
+}
+
diff --git a/src/UserLogin-master/UserLogin-master/User/User.iml b/src/UserLogin-master/UserLogin-master/User/User.iml
new file mode 100644
index 0000000..b5bd503
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/User/User.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/User/UserLogin.java b/src/UserLogin-master/UserLogin-master/User/UserLogin.java
new file mode 100644
index 0000000..1fbce97
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/User/UserLogin.java
@@ -0,0 +1,64 @@
+package com.weh.User;
+
+import com.mysql.cj.jdbc.MysqlDataSource;
+import javax.swing.*;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+//匹配输入的登录数据,以及对数据库驱动的开启
+public class UserLogin {
+ Connection connection = null;
+ PreparedStatement prepare;
+ ResultSet resultSet;
+ boolean loginSuccess;
+
+ public UserLogin() throws SQLException, ClassNotFoundException {
+ //连接mysql数据库
+ try {
+ MysqlDataSource mysqlDataSource = new MysqlDataSource();
+ mysqlDataSource.setURL("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false");//本地IP:端口/数据库名
+ mysqlDataSource.setUser("root");//mysql数据库的用户名
+ mysqlDataSource.setPassword("123456");//密码
+ connection = mysqlDataSource.getConnection();
+ } catch (Exception e) {
+ JOptionPane.showMessageDialog(null, "数据库连接失败", "提示", JOptionPane.WARNING_MESSAGE);
+ }
+ }
+ public void readLogin(Login login) {
+ try {
+ String sql = "SELECT * FROM test.User WHERE UserID = ? AND UserPassword = ?";//查询语句
+ prepare = connection.prepareStatement(sql);//创建执行环境
+ prepare.setString(1, login.getId());
+ prepare.setString(2, login.getPassword());
+ resultSet = prepare.executeQuery();//执行查询语句,如数据匹配成功,则返回true
+ if (resultSet.next()) { //迭代查询
+ login.setLoginSuccess(true);
+ JOptionPane.showMessageDialog(null, "登录成功");
+ } else {
+ login.setLoginSuccess(false);
+ if (login.getId().isEmpty() || login.getPassword().isEmpty()) {
+ if (login.getId().isEmpty()) {
+ JOptionPane.showMessageDialog(null, "用户名不能为空!", "提示", JOptionPane.WARNING_MESSAGE);
+ }
+ if (login.getPassword().isEmpty()){
+ JOptionPane.showMessageDialog(null, "密码不能为空!","提示", JOptionPane.WARNING_MESSAGE);
+ }
+ }else{
+ JOptionPane.showMessageDialog(null, "用户名不存在!", "警告", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ //释放资源和空间
+ connection.close();
+ prepare.close();
+ resultSet.close();
+ loginSuccess = login.isLoginSuccess();
+ } catch (SQLException e) {
+ JOptionPane.showMessageDialog(null, "异常", "警告", JOptionPane.ERROR_MESSAGE);
+ }
+
+ }
+}
+
diff --git a/src/UserLogin-master/UserLogin-master/User/UserRegister.java b/src/UserLogin-master/UserLogin-master/User/UserRegister.java
new file mode 100644
index 0000000..239549d
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/User/UserRegister.java
@@ -0,0 +1,48 @@
+package com.weh.User;
+
+import com.mysql.cj.jdbc.MysqlDataSource;
+import javax.swing.*;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+//插入数据,以及对数据库驱动的开启
+public class UserRegister { //注册数据处理者
+ Connection connection = null;
+ PreparedStatement presql; //预处理对象
+
+ public UserRegister() throws SQLException {
+ try {
+ //连接mysql数据库
+ MysqlDataSource mysqlDataSource = new MysqlDataSource();
+ mysqlDataSource.setURL("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false");
+ mysqlDataSource.setUser("User");
+ mysqlDataSource.setPassword("");
+ connection = mysqlDataSource.getConnection();
+ } catch (SQLException throwables) {
+ JOptionPane.showMessageDialog(null,"数据库连接失败","警告",JOptionPane.WARNING_MESSAGE);
+ }
+ }
+ public void writeRegister(Register register){
+ int flag;
+ try {
+ String sql = "INSERT INTO test.User VALUES (?,?,?)"; //插入语句
+ presql = connection.prepareStatement(sql);
+ presql.setString(1,register.getId());
+ presql.setString(2,register.getPassword());
+ presql.setString(3,register.getName());
+ flag = presql.executeUpdate(); //成功插入式返回1
+ //释放资源和空间
+ connection.close();
+ presql.close();
+ if (flag!=0){
+ JOptionPane.showMessageDialog(null,"注册成功");
+ }else {
+ JOptionPane.showMessageDialog(null,"注册失败","提示",JOptionPane.WARNING_MESSAGE);
+ }
+ } catch (SQLException e) {
+ JOptionPane.showMessageDialog(null,"用户名已存在!","警告",JOptionPane.WARNING_MESSAGE);
+ }
+ }
+}
+
diff --git a/src/UserLogin-master/UserLogin-master/UserLogin-master.iml b/src/UserLogin-master/UserLogin-master/UserLogin-master.iml
new file mode 100644
index 0000000..005fd16
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/UserLogin-master.iml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/libs/mysql-connector-j-8.0.31.jar b/src/UserLogin-master/UserLogin-master/libs/mysql-connector-j-8.0.31.jar
new file mode 100644
index 0000000..8b74bb8
Binary files /dev/null and b/src/UserLogin-master/UserLogin-master/libs/mysql-connector-j-8.0.31.jar differ
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/.idea/.gitignore b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/.idea/.gitignore
new file mode 100644
index 0000000..50d9d22
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/.idea/.gitignore
@@ -0,0 +1,3 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/.idea/libraries/jdbc.xml b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/.idea/libraries/jdbc.xml
new file mode 100644
index 0000000..82451b5
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/.idea/libraries/jdbc.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/.idea/misc.xml b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/.idea/misc.xml
new file mode 100644
index 0000000..53c6aae
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/.idea/modules.xml b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/.idea/modules.xml
new file mode 100644
index 0000000..aab8690
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/README.md b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/README.md
new file mode 100644
index 0000000..296d6e9
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/README.md
@@ -0,0 +1,2 @@
+Java--用户登录界面(连接Mysql数据库)
+![输入图片说明](https://images.gitee.com/uploads/images/2022/0413/184214_a8326845_9840785.png "未标题-1.png")
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/.idea/.gitignore b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/.idea/.gitignore
new file mode 100644
index 0000000..50d9d22
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/.idea/.gitignore
@@ -0,0 +1,3 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/.idea/misc.xml b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/.idea/misc.xml
new file mode 100644
index 0000000..b09fb27
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/.idea/modules.xml b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/.idea/modules.xml
new file mode 100644
index 0000000..ca153bb
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/Login.class b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/Login.class
new file mode 100644
index 0000000..9906069
Binary files /dev/null and b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/Login.class differ
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/LoginDemo.class b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/LoginDemo.class
new file mode 100644
index 0000000..d3cabcc
Binary files /dev/null and b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/LoginDemo.class differ
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/Register.class b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/Register.class
new file mode 100644
index 0000000..1939a5a
Binary files /dev/null and b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/Register.class differ
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/RegisterDemo.class b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/RegisterDemo.class
new file mode 100644
index 0000000..07771fa
Binary files /dev/null and b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/RegisterDemo.class differ
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/User.iml b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/User.iml
new file mode 100644
index 0000000..b5bd503
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/User.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/UserLogin.class b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/UserLogin.class
new file mode 100644
index 0000000..83b2319
Binary files /dev/null and b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/UserLogin.class differ
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/UserRegister.class b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/UserRegister.class
new file mode 100644
index 0000000..b9d957b
Binary files /dev/null and b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/User/UserRegister.class differ
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/UserLogin-master.iml b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/UserLogin-master.iml
new file mode 100644
index 0000000..005fd16
--- /dev/null
+++ b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/UserLogin-master.iml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/libs/mysql-connector-j-8.0.31.jar b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/libs/mysql-connector-j-8.0.31.jar
new file mode 100644
index 0000000..8b74bb8
Binary files /dev/null and b/src/UserLogin-master/UserLogin-master/out/production/UserLogin-master/com/weh/libs/mysql-connector-j-8.0.31.jar differ