Eclipse+Java+Swing+Mysql实现网上订餐系统【建议收藏】(上)

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: Eclipse+Java+Swing+Mysql实现网上订餐系统【建议收藏】

一、系统介绍


1.开发环境


开发工具:Eclipse2021


JDK版本:jdk1.8


Mysql版本:8.0.13


2.技术选型


Java+Swing+Mysql


3.系统功能


用户


1.登录系统


2.注册系统


3.用户点餐


4.查询订单


5.修改密码


管理员


1.登录系统


2.新增套餐


3.维护套餐


4.订单管理


4.数据库

/*
 Navicat Premium Data Transfer
 Source Server         : MYSQL
 Source Server Type    : MySQL
 Source Server Version : 80013
 Source Host           : localhost:3306
 Source Schema         : swing_order_meal
 Target Server Type    : MySQL
 Target Server Version : 80013
 File Encoding         : 65001
 Date: 14/10/2021 16:35:40
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for goods
-- ----------------------------
DROP TABLE IF EXISTS `goods`;
CREATE TABLE `goods`  (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `goodsName` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `price` float NULL DEFAULT NULL,
  `goodsDesc` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `imageLink` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of goods
-- ----------------------------
INSERT INTO `goods` VALUES (1, '碳烤鸡肉寿司', 23.1, '鸡肉、生菜、海苔、寿司', 'E:\\codes\\BusinessCodes\\JavaSwing\\OrderMeal\\src\\images\\ss1.png');
INSERT INTO `goods` VALUES (2, '北海道寿司', 13.2, '鱼、甜辣酱、海苔、米饭', 'E:\\codes\\BusinessCodes\\JavaSwing\\OrderMeal\\src\\images\\ss2.png');
INSERT INTO `goods` VALUES (3, '鳗鱼爆浆寿司', 43.2, '鱼、甜辣酱、海苔、米饭', 'E:\\codes\\BusinessCodes\\JavaSwing\\OrderMeal\\src\\images\\ss4.png');
-- ----------------------------
-- Table structure for order_goods
-- ----------------------------
DROP TABLE IF EXISTS `order_goods`;
CREATE TABLE `order_goods`  (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `orderId` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `goodsTotalPrice` float NULL DEFAULT NULL,
  `goodsId` int(10) NULL DEFAULT NULL,
  `goodsPrice` float NULL DEFAULT NULL,
  `goodsNum` int(10) NULL DEFAULT NULL,
  `goodsName` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `FK_order_goods_2`(`orderId`) USING BTREE,
  INDEX `FK_order_goods_1`(`goodsId`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 46 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of order_goods
-- ----------------------------
INSERT INTO `order_goods` VALUES (44, '20190319141543', 43.2, 3, 43.2, 1, '鳗鱼爆浆寿司');
INSERT INTO `order_goods` VALUES (45, '20190319141543', 13.2, 2, 13.2, 1, '北海道寿司');
INSERT INTO `order_goods` VALUES (46, '20211014114920', 23.1, 1, 23.1, 1, '碳烤鸡肉寿司');
INSERT INTO `order_goods` VALUES (47, '20211014161704', 23.1, 1, 23.1, 1, '碳烤鸡肉寿司');
INSERT INTO `order_goods` VALUES (48, '20211014162614', 13.2, 2, 13.2, 1, '北海道寿司');
-- ----------------------------
-- Table structure for order_info
-- ----------------------------
DROP TABLE IF EXISTS `order_info`;
CREATE TABLE `order_info`  (
  `orderId` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `orderStatus` int(10) NULL DEFAULT NULL,
  `orderNum` int(10) NULL DEFAULT NULL,
  `orderTotalMoney` float NULL DEFAULT NULL,
  `userName` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`orderId`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of order_info
-- ----------------------------
INSERT INTO `order_info` VALUES ('20211014114920', 3, 1, 23.1, '1');
INSERT INTO `order_info` VALUES ('20211014161704', 3, 1, 23.1, 'user');
INSERT INTO `order_info` VALUES ('20211014162614', 0, 1, 13.2, 'user');
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user`  (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `userName` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `password` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `email` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `rank` int(1) NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES (1, 'admin', 'admin', NULL, 1);
INSERT INTO `user` VALUES (11, 'user', 'user', '121232131@qq.com', 0);
SET FOREIGN_KEY_CHECKS = 1;


二、系统展示


1.登录系统


1517e6507b1545daad490ddbd3b49383.jpg


2.用户-注册系统


98596f4f0cd3467e8b0c1a4c1126f8aa.jpg


3.用户-主界面


c3c529d3acc2481d925c4ea7704caba4.jpg


4.用户-用户点餐


d40e7c35e709476ba45b3912f9d54fdb.jpg


5.用户-查询订单


b5bac30487024e3c88c0210f364a350d.jpg


6.用户-修改密码


6823c773afa44097993bcf14506ac1fd.jpg


7.管理员-主界面


2a517e7700d3417ca5108317b7637575.jpg


8.管理员-新增套餐


80f476bd7e5e4dd09366139c0ae4c999.jpg


9.管理员-维护套餐


81387fd4fe2649709abeb8c81dd5b107.jpg


10.管理员-订单管理


675cc82180da4cd881ec85252d2e092d.jpg


三、部分代码


LogOnFrm.java

/*
 * LogOnFrm.java
 *
 * Created on __DATE__, __TIME__
 */
package com.sjsq.client;
import java.awt.Color;
import java.awt.Font;
import java.sql.Connection;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import com.sjsq.common.User;
import com.sjsq.server.UserDao;
import com.sjsq.utils.DbUtil;
import com.sjsq.utils.StringUtil;
/**
 * 用户登陆
 * 
 * @author __USER__
 */
public class LogOnFrm extends javax.swing.JFrame {
  DbUtil dbUtil = new DbUtil();
  UserDao userDao = new UserDao();
  public static User s_currentUser = null;// 保存登陆用户的参数
  /** Creates new form LogOnFrm */
  public LogOnFrm() {
    // 改变系统默认字体
    Font font = new Font("Dialog", Font.PLAIN, 12);
    java.util.Enumeration keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
      Object key = keys.nextElement();
      Object value = UIManager.get(key);
      if (value instanceof javax.swing.plaf.FontUIResource) {
        UIManager.put(key, font);
      }
    }
    initComponents();
    // 设置frame居中显示
    this.setLocationRelativeTo(null);
  }
  // GEN-BEGIN:initComponents
  // <editor-fold defaultstate="collapsed" desc="Generated Code">
  private void initComponents() {
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jb_logon = new javax.swing.JButton();
    jb_register = new javax.swing.JButton();
    userNameTxt = new javax.swing.JTextField();
    passwordTxt = new javax.swing.JPasswordField();
    jb_reset = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("网上订餐系统");
    setResizable(false);
    jLabel1.setFont(new java.awt.Font("宋体", 1, 24));
    jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/OrderMeal.png"))); // NOI18N
    jLabel1.setText("餐厅点餐系统欢迎您");
    jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/userName.png"))); // NOI18N
    jLabel2.setText("用户名:");
    jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/password.png"))); // NOI18N
    jLabel3.setText("密   码:");
    jb_logon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/login.png"))); // NOI18N
    jb_logon.setText("登录");
    jb_logon.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_logonActionPerformed(evt);
      }
    });
    jb_register.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/register.png"))); // NOI18N
    jb_register.setText("注册");
    jb_register.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_registerActionPerformed(evt);
      }
    });
    jb_reset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/reset.png"))); // NOI18N
    jb_reset.setText("重置");
    jb_reset.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_resetActionPerformed(evt);
      }
    });
    setBackground(Color.WHITE);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
        javax.swing.GroupLayout.Alignment.TRAILING,
        layout.createSequentialGroup().addGap(52, 52, 52).addGroup(layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2).addComponent(jLabel3))
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(passwordTxt).addComponent(userNameTxt,
                        javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addGroup(
                javax.swing.GroupLayout.Alignment.LEADING,
                layout.createSequentialGroup().addGap(8, 8, 8).addComponent(jb_logon).addGap(18, 18, 18)
                    .addComponent(jb_reset).addGap(18, 18, 18).addComponent(jb_register))
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 304,
                    javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addContainerGap(54, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(18, 18, 18)
        .addComponent(
            jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addGap(27, 27, 27)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2)
            .addComponent(userNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addGap(38, 38, 38)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel3)
            .addComponent(passwordTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addGap(37, 37, 37).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
            .addComponent(jb_logon).addComponent(jb_reset).addComponent(jb_register))
        .addContainerGap(55, Short.MAX_VALUE)));
    pack();
  }// </editor-fold>
    // GEN-END:initComponents
  // 显示注册页面
  private void jb_registerActionPerformed(java.awt.event.ActionEvent evt) {
    this.dispose();
    new RegisterFrm().setVisible(true);
  }
  // 登陆验证显示登陆以后界面
  private void jb_logonActionPerformed(java.awt.event.ActionEvent evt) {
    String userName = this.userNameTxt.getText();
    String password = new String(this.passwordTxt.getPassword());
    if (StringUtil.isEmpty(userName)) {
      JOptionPane.showMessageDialog(null, "用户名不能为空");
      return;
    }
    if (StringUtil.isEmpty(password)) {
      JOptionPane.showMessageDialog(null, "密码不能为空");
      return;
    }
    User user = new User(userName, password);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      User currentUser = userDao.login(con, user);
      if (currentUser != null) {
        s_currentUser = currentUser;// 保存登陆的用户
        int role = currentUser.getRank();
        if (role == 1) {
          this.dispose();
          new AdminFrm().setVisible(true);// 进入管理员页面
        } else if (role == 0) {
          this.dispose();
          new UserOrderFrm().setVisible(true);// 进入用户点餐界面
        }
      } else {
        JOptionPane.showMessageDialog(null, "用户名或密码错误");
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, "用户名或密码错误");
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
  // 重置文本框内容
  private void jb_resetActionPerformed(java.awt.event.ActionEvent evt) {
    this.passwordTxt.setText("");
    this.userNameTxt.setText("");
  }
  /**
   * @param args
   *            the command line arguments
   */
  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        new LogOnFrm().setVisible(true);
      }
    });
  }
  // GEN-BEGIN:variables
  // Variables declaration - do not modify
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JButton jb_logon;
  private javax.swing.JButton jb_register;
  private javax.swing.JButton jb_reset;
  private javax.swing.JPasswordField passwordTxt;
  private javax.swing.JTextField userNameTxt;
  // End of variables declaration//GEN-END:variables
}

RegisterFrm.java

/*
 * RegisterFrm.java
 *
 * Created on __DATE__, __TIME__
 */
package com.sjsq.client;
import java.sql.Connection;
import javax.swing.JOptionPane;
import com.sjsq.common.User;
import com.sjsq.server.UserDao;
import com.sjsq.utils.DbUtil;
import com.sjsq.utils.StringUtil;
/**
 * 注册
 * @author __USER__
 */
public class RegisterFrm extends javax.swing.JFrame {
  DbUtil dbUtil = new DbUtil();
  UserDao userDao = new UserDao();
  /** Creates new form RegisterFrm */
  public RegisterFrm() {
    initComponents();
    // 设置frame居中显示
    this.setLocationRelativeTo(null);
  }
  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  // GEN-BEGIN:initComponents
  // <editor-fold defaultstate="collapsed" desc="Generated Code">
  private void initComponents() {
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jb_register = new javax.swing.JButton();
    jb_reset = new javax.swing.JButton();
    userNameTxt = new javax.swing.JTextField();
    emailTxt = new javax.swing.JTextField();
    passwordTxt = new javax.swing.JPasswordField();
    passwordConfirmTxt = new javax.swing.JPasswordField();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("用户注册");
    setResizable(false);
    jLabel1.setFont(new java.awt.Font("宋体", 1, 18));
    jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/new_register.png"))); // NOI18N
    jLabel1.setText("新用户注册");
    jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/new_user.png"))); // NOI18N
    jLabel2.setText("用户名:");
    jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/new_password.png"))); // NOI18N
    jLabel3.setText("密码:");
    jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/password_config.png"))); // NOI18N
    jLabel4.setText("确认密码:");
    jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/email.png"))); // NOI18N
    jLabel5.setText("邮箱:");
    jb_register.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/register.png"))); // NOI18N
    jb_register.setText("注册");
    jb_register.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_registerActionPerformed(evt);
      }
    });
    jb_reset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/reset.png"))); // NOI18N
    jb_reset.setText("重置");
    jb_reset.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jb_resetActionPerformed(evt);
      }
    });
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(95, 95, 95).addComponent(jLabel1))
                .addGroup(layout.createSequentialGroup().addGap(57, 57, 57).addComponent(jb_register)
                    .addGap(63, 63, 63).addComponent(jb_reset)))
            .addContainerGap())
        .addGroup(layout.createSequentialGroup().addGap(40, 40, 40)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel2).addComponent(jLabel5).addComponent(jLabel3)
                .addComponent(jLabel4))
            .addGap(28, 28, 28)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(passwordConfirmTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 146,
                    Short.MAX_VALUE)
                .addComponent(emailTxt, javax.swing.GroupLayout.Alignment.LEADING,
                    javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                .addComponent(userNameTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                .addComponent(passwordTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE))
            .addGap(40, 40, 40)));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(19, 19, 19).addComponent(jLabel1).addGap(18, 18, 18)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2)
            .addComponent(userNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel3)
            .addComponent(passwordTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel4)
            .addComponent(passwordConfirmTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
            .addComponent(emailTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jLabel5))
        .addGap(28, 28, 28).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
            .addComponent(jb_register).addComponent(jb_reset))
        .addGap(55, 55, 55)));
    pack();
  }// </editor-fold>
    // GEN-END:initComponents
    // 注册验证操作
  private void jb_registerActionPerformed(java.awt.event.ActionEvent evt) {
    String userName = this.userNameTxt.getText();
    String password = new String(this.passwordTxt.getPassword());
    String passwordConfirm = new String(this.passwordConfirmTxt.getPassword());
    String email = this.emailTxt.getText();
    if (StringUtil.isEmpty(userName)) {
      JOptionPane.showMessageDialog(null, "用户名不能为空");
      return;
    }
    if (StringUtil.isEmpty(password)) {
      JOptionPane.showMessageDialog(null, "密码不能为空");
      return;
    }
    if (!password.equals(passwordConfirm)) {
      JOptionPane.showMessageDialog(null, "两次输入的密码不一致!");
      return;
    }
    if (!StringUtil.checkEmail(email)) {
      JOptionPane.showMessageDialog(null, "邮箱格式错误!");
      return;
    }
    User user = new User(userName, password, email);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      if (!userDao.isUserExist(con, user)) {
        int addNum = userDao.userAdd(con, user);
        if (addNum == 1) {
          JOptionPane.showMessageDialog(null, "注册成功!");
          this.dispose();
          new LogOnFrm().setVisible(true);
        } else {
          JOptionPane.showMessageDialog(null, "注册失败");
        }
      } else {
        JOptionPane.showMessageDialog(null, "用户名存在,请重新输入!");
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, "注册失败,请重新注册!");
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
  // 重置表单
  private void jb_resetActionPerformed(java.awt.event.ActionEvent evt) {
    this.userNameTxt.setText("");
    this.passwordTxt.setText("");
    this.passwordConfirmTxt.setText("");
    this.emailTxt.setText("");
  }
  /**
   * @param args
   *            the command line arguments
   */
  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        new RegisterFrm().setVisible(true);
      }
    });
  }
  // GEN-BEGIN:variables
  // Variables declaration - do not modify
  private javax.swing.JTextField emailTxt;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JButton jb_register;
  private javax.swing.JButton jb_reset;
  private javax.swing.JPasswordField passwordConfirmTxt;
  private javax.swing.JPasswordField passwordTxt;
  private javax.swing.JTextField userNameTxt;
  // End of variables declaration//GEN-END:variables
}
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
29天前
|
监控 Java API
如何使用Java语言快速开发一套智慧工地系统
使用Java开发智慧工地系统,采用Spring Cloud微服务架构和前后端分离设计,结合MySQL、MongoDB数据库及RESTful API,集成人脸识别、视频监控、设备与环境监测等功能模块,运用Spark/Flink处理大数据,ECharts/AntV G2实现数据可视化,确保系统安全与性能,采用敏捷开发模式,提供详尽文档与用户培训,支持云部署与容器化管理,快速构建高效、灵活的智慧工地解决方案。
|
20天前
|
设计模式 消息中间件 搜索推荐
Java 设计模式——观察者模式:从优衣库不使用新疆棉事件看系统的动态响应
【11月更文挑战第17天】观察者模式是一种行为设计模式,定义了一对多的依赖关系,使多个观察者对象能直接监听并响应某一主题对象的状态变化。本文介绍了观察者模式的基本概念、商业系统中的应用实例,如优衣库事件中各相关方的动态响应,以及模式的优势和实际系统设计中的应用建议,包括事件驱动架构和消息队列的使用。
|
1月前
|
Java Android开发
Eclipse Java 构建路径
Eclipse Java 构建路径
33 3
|
1月前
|
Java Android开发
Eclipse 创建 Java 项目
Eclipse 创建 Java 项目
39 4
|
1月前
|
Java Android开发
Eclipse 创建 Java 接口
Eclipse 创建 Java 接口
27 1
|
1月前
|
Java Android开发
Eclipse 创建 Java 包
Eclipse 创建 Java 包
31 1
|
1月前
|
Java Android开发
Eclipse 创建 Java 类
Eclipse 创建 Java 类
26 0
|
6天前
|
安全 Java API
java如何请求接口然后终止某个线程
通过本文的介绍,您应该能够理解如何在Java中请求接口并根据返回结果终止某个线程。合理使用标志位或 `interrupt`方法可以确保线程的安全终止,而处理好网络请求中的各种异常情况,可以提高程序的稳定性和可靠性。
36 6
|
21天前
|
设计模式 Java 开发者
Java多线程编程的陷阱与解决方案####
本文深入探讨了Java多线程编程中常见的问题及其解决策略。通过分析竞态条件、死锁、活锁等典型场景,并结合代码示例和实用技巧,帮助开发者有效避免这些陷阱,提升并发程序的稳定性和性能。 ####
|
19天前
|
存储 监控 小程序
Java中的线程池优化实践####
本文深入探讨了Java中线程池的工作原理,分析了常见的线程池类型及其适用场景,并通过实际案例展示了如何根据应用需求进行线程池的优化配置。文章首先介绍了线程池的基本概念和核心参数,随后详细阐述了几种常见的线程池实现(如FixedThreadPool、CachedThreadPool、ScheduledThreadPool等)的特点及使用场景。接着,通过一个电商系统订单处理的实际案例,分析了线程池参数设置不当导致的性能问题,并提出了相应的优化策略。最终,总结了线程池优化的最佳实践,旨在帮助开发者更好地利用Java线程池提升应用性能和稳定性。 ####

推荐镜像

更多
下一篇
DataWorks