一、系统介绍
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.登录系统
2.用户-注册系统
3.用户-主界面
4.用户-用户点餐
5.用户-查询订单
6.用户-修改密码
7.管理员-主界面
8.管理员-新增套餐
9.管理员-维护套餐
10.管理员-订单管理
三、部分代码
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 }