一、项目名称
基于JAVASE的电子商城系统
摘要信息:
电子商城系统主要功能包括:用户注册、用户登录、用户查看商城商品、用户购买商品、用户查看购物车并且清空购物车、用户找回账户以及密码、管理员登录、管理员注册、管理员查看用户信息、管理员删除用户信息、管理员删除商品信息、管理员添加商品信息、管理员修改商品信息、退出登录等。 
图形可视化界面运行下能够显示系统启动进度条,删除、添加、注册等相关操作时能够弹出窗口加以提示,退出登录或系统时能够做到单击确认退出按钮才退出登录或系统,能够对用户加以提示。 
注册用户或是管理员、添加商品信息、购买商品、删除商品或是用户信息、修改商品信息等相关操作时能够判断有无该用户或是商品。 
用户在购买商品的时候同时更新商品的库存数量,管理员删除管理员时可以做到同时删除用户的购买信息。
二、功能要求
1、用户注册 2、用户登录 3、用户查看商品列表 4、用户购买商品 5、用户查看购买商品列表 6、用户清空购物车 7、用户找回账户和密码 8、管理员登录 
9、管理员注册 10、查看用户信息 11、查看商品信息 12、删除用户信息 13、删除商品信息 14、添加商品信息 15、修改商品信息 16、退出用户登录 
17、退出管理员登录 18、退出商城
三、需求分析
该系统的用户是商城消费者和商城管理者,根据客户的要求,可以注册、登录、购物、查看购物车信息、找回账户和密码,管理员可以对商品信息进行增加、修改、删除操作,可以对用户进行查看和删除。
数据库表:
admin表:
cost表:
goods表:
user表:
四、设计思想
在控制台与图形可视化界面下运行
使用Mysql数据库存取用户登录信息和商品信息
使用List存取商品购买信息
把程序分为多个类,多个类之间的互相调用。
用户或是管理员进行注册、登录时能够提供校验码。
用户或是管理员获取数据库信息时能够与数据库进行交互。
用户购物要做到简洁明了。
用户只需要身份证号码和邮箱地址就能找回账户和密码。
注册、删除、修改等操作要有信息提示。
用户、管理员进行操作时能够做到操作提示与用户名提示。
退出登录或是退出系统时能够做到让用户有所考虑。
五、具体实现
1、技术思路:
 * 界面:基于控制台与图形可视化界面(Swing)实现用户的输入和输出。
 * 程序流程:在函数中利用循环与递归 ,读取用户输入,调用模块实现各个子功能。 
2、功能子模块划分:
 * 注册模块
 * 登录模块
 * 查看商品模块(查看商品列表,购买商品)
 * 查看购买商品信息
 * 管理员登录(添加管理员信息,对商品信息进行查看、增加、修改、删除,对用户信息进行查看、删除,删除用户信息时能够做到同时删除消费记录)
 * 退出系统 
六、运行截图
商城系统启动进度条(进度条能够做到动态加载):
商城主界面:
用户注册界面(填写注册信息不符合要求时能够弹窗提示、并且判断用户名是否重复等):
用户登录界面(账户、密码不一致时能弹窗提示):
用户服务选择界面(能够提示用户名):
购买商品界面(能够判断输入的商品序号是否正确):
查看购物车界面(能够一键清空购物车):
查看商城商品信息界面:
管理员登录界面:
找回账户与密码界面:
管理员服务选择界面:
添加管理员界面:
查看用户信息界面:
删除用户信息界面:
删除商品信息界面:
添加商品信息界面:
修改商品信息界面:
退出账号、管理员登录、商城系统时要有提示:
七、源代码 (程序主要源代码):
1、启动加载进度条:
public ProgressBar() { setTitle("欢迎使用 Hern 电子商城"); setBounds(600,600,400,200); 
setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel 
contentPane = new JPanel(); contentPane.setLayout(new FlowLayout());//设置面板为流式布局 
label.setText("正在进入 Hern 电子商城..."); label.setFont(new java.awt.Font("微软雅黑", 
1,18));//设置字体格式、粗细、大小 label1.setText(" "); 
processBar.setStringPainted(true);//设置显示信息 
processBar.setBackground(Color.darkGray);//设置背景色 
processBar.setForeground(Color.BLUE);//设置前景色 new Thread() { public void run() { 
for (int i = 0; i < 100; i += 5) { try { Thread.sleep(100); // 让当前线程休眠 } catch 
(InterruptedException e) { e.printStackTrace(); } processBar.setValue(i); // 
设置进度条数值 } processBar.setString("单击 进入 按钮 进入商城");// 设置提示信息 } }.start(); 
button.setText("进 入"); button.setFont(new Font("微软雅黑",1,18)); 
button.addActionListener(new ActionListener() { @Override public void 
actionPerformed(ActionEvent e) { // TODO Auto-generated method stub 
if(e.getSource() == button) { dispose(); IndexWelcome index = new 
IndexWelcome(); } } }); box1.add(label);//文本标签 box2.add(label1);//空白文本标签 
box3.add(processBar);//进度条 box4.add(button); 
base.add(box1);//把水平盒子添加到垂直盒子中,让其变成垂直布局 base.add(box2); base.add(box3); 
base.add(Box.createVerticalStrut(30)); base.add(box4); contentPane.add(base);// 
向面板添加垂直盒子 add(contentPane);//向窗体中添加面板 } 
2、商城主界面:
public IndexWelcome() { setTitle("欢迎使用 Hern 电子商城"); 
setBounds(300,100,900,900); setVisible(true); 
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contenctPanel.setLayout(new 
FlowLayout(FlowLayout.CENTER, 5, 5)); contenctPanel.setBackground(Color.WHITE); 
label.setText("H e r n 电 子 商 城"); label.setFont(new Font("微软雅黑",1,32)); 
label.setForeground(Color.BLUE); label1.setText("商 城 主 界 面"); 
label1.setFont(new Font("微软雅黑",0,25)); button1.setText("1、用 户 注 册"); 
button1.setBackground(Color.WHITE); button1.setFont(new Font("微软雅黑",0,18)); 
button1.setBorderPainted(false); button2.setText("2、用 户 登 录"); 
button2.setBackground(Color.WHITE); button2.setFont(new Font("微软雅黑",0,18)); 
button2.setBorderPainted(false); button3.setText("3、查 看 商 城 商 品"); 
button3.setBackground(Color.WHITE); button3.setFont(new Font("微软雅黑",0,18)); 
button3.setBorderPainted(false); button4.setText("4、查 看 我 购 买 的 商 品"); 
button4.setBackground(Color.WHITE); button4.setFont(new Font("微软雅黑",0,18)); 
button4.setBorderPainted(false); button5.setText("5、管 理 员 登 录"); 
button5.setBackground(Color.WHITE); button5.setFont(new Font("微软雅黑",0,18)); 
button5.setBorderPainted(false); button6.setText("6、找 回 账 户、密 码"); 
button6.setBackground(Color.WHITE); button6.setFont(new Font("微软雅黑",0,18)); 
button6.setBorderPainted(false); button7.setText("7、退出 Hern 电子商城"); 
button7.setBackground(Color.WHITE); button7.setFont(new Font("微软雅黑",0,18)); 
button7.setBorderPainted(false); /***用户注册***/ button1.addActionListener(new 
ActionListener() { @Override public void actionPerformed(ActionEvent e) { // 
TODO Auto-generated method stub if(e.getSource() == button1) { dispose();//销毁窗体 
UserRegion region = new UserRegion(); } } }); /***用户登录***/ 
button2.addActionListener(new ActionListener() { @Override public void 
actionPerformed(ActionEvent e) { // TODO Auto-generated method stub 
if(e.getSource() == button2) { dispose();//销毁窗体 UserLogin login = new 
UserLogin(); } } }); /***查看商城商品***/ button3.addActionListener(new 
ActionListener() { @Override public void actionPerformed(ActionEvent e) { // 
TODO Auto-generated method stub if(e.getSource() == button3) { dispose();//销毁窗体 
GoodsLook look = new GoodsLook(); } } }); /***查看我购买的商品***/ 
button4.addActionListener(new ActionListener() { @Override public void 
actionPerformed(ActionEvent e) { // TODO Auto-generated method stub 
if(e.getSource() == button4) { dispose();//销毁窗体 UserLogin login = new 
UserLogin(); } } }); /***管理员登录***/ button5.addActionListener(new 
ActionListener() { @Override public void actionPerformed(ActionEvent e) { // 
TODO Auto-generated method stub if(e.getSource() == button5) { dispose();//销毁窗体 
AdminLogin admin = new AdminLogin(); } } }); /***找回账户、密码***/ 
button6.addActionListener(new ActionListener() { @Override public void 
actionPerformed(ActionEvent e) { // TODO Auto-generated method stub 
if(e.getSource() == button6) { dispose();//销毁窗体 UserSearch search = new 
UserSearch(); } } }); /***退出系统***/ button7.addActionListener(new 
ActionListener() { @Override public void actionPerformed(ActionEvent e) { // 
TODO Auto-generated method stub if(e.getSource() == button7) { Option option = 
new Option(); dispose(); } } }); } 
 3、用户注册:
public UserRegion(){ setTitle("欢迎使用 Hern 电子商城"); setBounds(300,100,900,900); 
setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
contenctPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); 
contenctPanel.setBackground(Color.WHITE); label.setText("H e r n 电 子 商 城"); 
label.setFont(new Font("微软雅黑",1,32)); label.setForeground(Color.BLUE); 
label0.setText("用 户 注 册 界 面\n"); label0.setFont(new Font("微软雅黑",1,25)); //用户名 
label1.setText("用户名(字母和数字):"); label1.setFont(new Font("微软雅黑",0,18)); 
field.addActionListener(new Myaction()); //密码 label2.setText("密 码(字母和数字):"); 
label2.setFont(new Font("微软雅黑",0,18)); field1.addActionListener(new 
Myaction()); password1.setText(password); //身份证号码 label3.setText("居 民 身 份 证 号 码 
:"); label3.setFont(new Font("微软雅黑",0,18)); field2.addActionListener(new 
Myaction()); //年龄 int a; label4.setText("年 龄(18 ~ 65 岁之间):"); 
label4.setFont(new Font("微软雅黑",0,18)); field3.addActionListener(new 
Myaction()); //邮箱地址 label5.setText("电 子 邮 箱 地 址:"); label5.setFont(new 
Font("微软雅黑",0,18)); field4.addActionListener(new Myaction()); //联系地址 
label6.setText("个 人 联 系 地 址:"); label6.setFont(new Font("微软雅黑",0,18)); 
field5.addActionListener(new Myaction()); //随机验证码 Rand rand= new Rand(); int 
num = rand.getRandom(); label7.setText("输 入 验 证 码 ( "+ num +" ):"); 
label7.setFont(new Font("微软雅黑",0,18)); field6.addActionListener(new 
ActionListener() { @Override public void actionPerformed(ActionEvent e) { // 
TODO Auto-generated method stub if(e.getSource() == field6) { String str = 
field6.getText(); int n = Integer.parseInt(str); if(n != num) { 
JOptionPane.showMessageDialog(null,"验证码不正确", "错误",JOptionPane.ERROR_MESSAGE); 
field6.setText(""); } } } }); button.setText("注册"); button.setFont(new 
Font("微软雅黑",0,18)); button.addActionListener(new Myaction()); 
button1.setText("返回商城主界面"); button1.setFont(new Font("微软雅黑",1,18)); 
button1.setBorderPainted(false); button1.setBackground(Color.WHITE); 
button1.addActionListener(new ActionListener() { @Override public void 
actionPerformed(ActionEvent e) { // TODO Auto-generated method stub 
if(e.getSource() == button1) { dispose(); IndexWelcome welcome = new 
IndexWelcome(); } } }); } class Myaction extends JFrame implements 
ActionListener{ @Override public void actionPerformed(ActionEvent e) { 
DBuserNamedecide dbusername = new DBuserNamedecide();//检查用户名是否重复 UserDecide 
userdecide = new UserDecide();//检查用户名和密码是否为英文和数字组合,并且检查邮箱符不符合规范 DBuserregion 
insert = new DBuserregion();//把用户信息添加到数据库 // TODO Auto-generated method stub 
if(e.getSource() == button) { //获取文本框输入的信息 username = field.getText(); password 
= password1.getText(); card = field2.getText(); String str = field3.getText(); 
age= Integer.parseInt(str); useremail = field4.getText(); address = 
field5.getText(); String option =username + " 用户恭喜您注册成功"; 
//判断用户名、密码、年龄、身份证、邮箱地址,正确无误之后插入数据库 if(userdecide.Decide(username) == false || 
dbusername.decideUsername(username)) { 
JOptionPane.showMessageDialog(null,"用户名不能重复,由字母和数字组成,至少为6位!", 
"错误",JOptionPane.ERROR_MESSAGE); field.setText(""); }else 
if(userdecide.Decide(password) == false) { 
JOptionPane.showMessageDialog(null,"密码必须由字母和数字组成,至少为6位!", 
"错误",JOptionPane.ERROR_MESSAGE); field1.setText(""); }else if(card.length() != 
18) { JOptionPane.showMessageDialog(null,"身份证号码不符合要求!", 
"错误",JOptionPane.ERROR_MESSAGE); field2.setText(""); }else if(age < 18 || age > 
65) { JOptionPane.showMessageDialog(null,"年龄必须在 18~65 之间!", 
"错误",JOptionPane.ERROR_MESSAGE); field3.setText(""); }else 
if(userdecide.Email(useremail) == false) { 
JOptionPane.showMessageDialog(null,"电子邮箱地址不正确!", 
"错误",JOptionPane.ERROR_MESSAGE); field4.setText(""); }else 
if(insert.insertUser(username, password, card, age, useremail, address)) { 
JOptionPane.showMessageDialog(null, option, "正确注册",JOptionPane.DEFAULT_OPTION); 
IndexWelcome welcome = new IndexWelcome(); dispose(); } } } } 
 4、用户登录:
public UserLogin() { setTitle("欢迎使用 Hern 电子商城"); setBounds(300,100,900,900); 
setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
contenctPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); 
contenctPanel.setBackground(Color.WHITE); label.setText("H e r n 电 子 商 城"); 
label.setFont(new Font("微软雅黑",1,32)); label.setForeground(Color.BLUE); 
label0.setText("用 户 登 录 界 面\n"); label0.setFont(new Font("微软雅黑",1,25)); //用户名 
label1.setText("请 输 入 用 户 名:"); label1.setFont(new Font("微软雅黑",0,18)); 
field.addActionListener(new Myaction()); //密码 label2.setText("请 输 入 密 码:"); 
label2.setFont(new Font("微软雅黑",0,18)); field1.addActionListener(new 
Myaction()); password1.setText(password); //随机验证码 Rand rand= new Rand(); int 
num = rand.getRandom(); label3.setText("验 证 码 ( "+ num +" ):"); 
label3.setFont(new Font("微软雅黑",0,18)); field2.addActionListener(new 
ActionListener() { @Override public void actionPerformed(ActionEvent e) { // 
TODO Auto-generated method stub if(e.getSource() == field2) { String str = 
field2.getText(); int n = Integer.parseInt(str); if(n != num) { 
JOptionPane.showMessageDialog(null,"验证码不正确", "错误",JOptionPane.ERROR_MESSAGE); 
field2.setText(""); } } } });  //返回商城主界面 button1.setText(" 返回商城主界面"); 
button1.setFont(new Font("微软雅黑",1,18)); button1.setBorderPainted(false); 
button1.setBackground(Color.WHITE); button1.addActionListener(new 
ActionListener() { @Override public void actionPerformed(ActionEvent e) { // 
TODO Auto-generated method stub if(e.getSource() == button1) { dispose(); 
IndexWelcome welcome = new IndexWelcome(); } } }); } class Myaction extends 
JFrame implements ActionListener{ @Override public void 
actionPerformed(ActionEvent e) { // TODO Auto-generated method stub 
DBuserPassdecide passdecide = new DBuserPassdecide(); DBuserNamedecide 
namedecide = new DBuserNamedecide(); if(e.getSource() == button) { //获取文本框输入的信息 
username = field.getText(); password = password1.getText(); //判断用户名、密码 
if(namedecide.decideUsername(username) == false) { 
JOptionPane.showMessageDialog(null,"用户不存在,请重新输入!", 
"错误",JOptionPane.ERROR_MESSAGE); field.setText(""); }else 
if(passdecide.decideUserpass(username, password) == false) { 
JOptionPane.showMessageDialog(null,"密码不正确,请重新输入!", 
"错误",JOptionPane.ERROR_MESSAGE); field1.setText(""); }else{ dispose(); 
UserSelect userselect = new UserSelect(username);//跳转到用户服务选择界面 
userselect.getName(username); } } } }