基于java的Swing+MySQL电子商城(java+swing+mysql+gui)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

管理员管理商品、用户购买商品等

eclipse运行:

540123072502

idea运行:

530123072502

前台用户:

350123072502

360123072502

370123072502

390123072502

400123072502

410123072502

420123072502

430123072502

后台管理员:

440123072502

450123072502

460123072502

470123072502

480123072502

500123072502

510123072502

520123072502

技术框架

Java Swing GUI

基于java的Swing+MySQL电子商城(java+swing+mysql+gui)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
box.add(label);
box1.add(label0);
box2.add(label1);
box3.add(scroll);
box4.add(label2);
box5.add(label3);
box5.add(field);
box6.add(label4);
box6.add(field1);
box7.add(label5);
box7.add(field2);
box8.add(label6);
box8.add(field3);
box9.add(label7);
box9.add(field4);
box10.add(label8);
box10.add(field5);
box11.add(button);
box11.add(button1);

base.add(box);
base.add(Box.createVerticalStrut(10));
base.add(box0);
base.add(Box.createVerticalStrut(10));
base.add(box1);
base.add(Box.createVerticalStrut(10));
base.add(box2);
base.add(Box.createVerticalStrut(10));
base.add(box3);
base.add(Box.createVerticalStrut(30));
base.add(box4);
base.add(Box.createVerticalStrut(30));
base.add(box5);
base.add(Box.createVerticalStrut(30));
base.add(box6);
base.add(Box.createVerticalStrut(30));
base.add(box7);
base.add(Box.createVerticalStrut(30));
base.add(box8);
base.add(Box.createVerticalStrut(30));
base.add(box9);
base.add(Box.createVerticalStrut(30));
base.add(box10);
base.add(Box.createVerticalStrut(40));
base.add(box11);
base.add(Box.createVerticalStrut(40));

contenctPanel.add(base);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
private final Box box6 = Box.createHorizontalBox();
private final Box box7 = Box.createHorizontalBox();
private final Box box8 = Box.createHorizontalBox();
private final Box box9 = Box.createHorizontalBox();

private String adminname;


public void getName(String name) {
this.adminname = name;
}

public AdminSelect(String adminname) {
setTitle("欢迎使用 在线 电子商城");
setBounds(300,100,900,900);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

contenctPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
contenctPanel.setBackground(Color.WHITE);
label.setText("在 线 电 子 商 城");
label.setFont(new Font("微软雅黑",1,32));
label.setForeground(Color.BLUE);

label0.setText("管 理 员 服 务 选 择 界 面\n");
label0.setFont(new Font("微软雅黑",1,25));

label1.setText("欢迎 " + adminname + " 管理员");
label1.setFont(new Font("微软雅黑",0,20));

button1.setText("1、添 加 新 管 理 员");
button1.setBackground(Color.WHITE);
button1.setFont(new Font("微软雅黑",1,18));
button1.setBorderPainted(false);
button1.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == button1) {
dispose();
AdminRegion region = new AdminRegion(adminname);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
				AdminGoodsUpdate Up = new AdminGoodsUpdate(adminname);
}
}

}
}
package com.shop.JFrame;
/***用户购买商品界面***/



public class UserBuy extends JFrame {

static Connection conn; //声明Connection对象
static PreparedStatement pres; //向数据库发送SQL语句
static ResultSet res; //执行数据库查询

private final JPanel contenctPanel = new JPanel();

private final JTextField field = new JTextField(10);
private final JTextField field1 = new JTextField(10);

private final JLabel label = new JLabel();
private final JLabel label0 = new JLabel();
private final JLabel label1 = new JLabel();
private final JLabel label2 = new JLabel();
private final JLabel label3 = new JLabel();
private final JLabel label4 = new JLabel();

private final JButton button = new JButton();
private final JButton button1 = new JButton();

private final Box base = Box.createVerticalBox();
private final Box box = Box.createHorizontalBox();
private final Box box1 = Box.createHorizontalBox();
private final Box box2 = Box.createHorizontalBox();
private final Box box3 = Box.createHorizontalBox();
private final Box box4 = Box.createHorizontalBox();
private final Box box5 = Box.createHorizontalBox();
private final Box box6 = Box.createHorizontalBox();
private final Box box7 = Box.createHorizontalBox();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
private final Box box1 = Box.createHorizontalBox();
private final Box box2 = Box.createHorizontalBox();
private final Box box3 = Box.createHorizontalBox();
private final Box box4 = Box.createHorizontalBox();
private final Box box5 = Box.createHorizontalBox();

private String username;

public void getName(String name) {
this.username = name;
}

public UserSelect(String username) {

setTitle("欢迎使用 在线 电子商城");
setBounds(300,100,900,900);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

contenctPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
contenctPanel.setBackground(Color.WHITE);
label.setText("在 线 电 子 商 城");
label.setFont(new Font("微软雅黑",1,32));
label.setForeground(Color.BLUE);

label0.setText("用 户 服 务 选 择 界 面\n");
label0.setFont(new Font("微软雅黑",1,25));


label1.setText("欢迎 " + username + " VIP用户");
label1.setFont(new Font("微软雅黑",0,20));
//购买商品
button.setText("1、 购 买 商 品 ");
button.setFont(new Font("微软雅黑",1,18));
button.setBorderPainted(false);
button.setBackground(Color.WHITE);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == button) {
dispose();
UserBuy buy = new UserBuy(username);
buy.getName(username);
}
}
});
//查看购物车
button2.setText("2、 查 看 购 物 车 ");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
		@Override
public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

DBadminNamedecide dbadminname = new DBadminNamedecide();
DBadminRegion insert = new DBadminRegion();
UserDecide userdecide = new UserDecide();
if(e.getSource() == button) {

//获取文本框输入的信息
username = field.getText();
password = password1.getText();

String option = username + " 管理员添加成功";

if(dbadminname.decideAdminname(username) == true || username.length() < 6 || userdecide.Decide(username) == false) {
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(insert.insertAdmin(username,password )) {
JOptionPane.showMessageDialog(null, option, "正确注册",JOptionPane.DEFAULT_OPTION);
AdminSelect select = new AdminSelect(adminname);
select.getName(adminname);
dispose();
}

}
}
}
}
package com.shop.JFrame;
/***管理员删除商品信息界面***/



public class AdminGoodsDel extends JFrame {

private String adminname;
static Connection conn; //声明Connection对象
static PreparedStatement pres; //向数据库发送SQL语句
static ResultSet res; //执行数据库查询
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
					field1.setText("");
}else {
String name = goodsname.getgoodsName(id);//获取商品名称
BigDecimal vip = money.getgoodsVIPmoney(id);//获取商品价格
BigDecimal cost = vip.multiply(BigDecimal.valueOf(num));
if(insert.Goodsinsert(username, id, name, vip, num, cost)) {
JOptionPane.showMessageDialog(null, name + " 商 品 购 买 成 功 !", "购买成功",JOptionPane.DEFAULT_OPTION);
update.setupgoodsNum(id, n-num);//同时更新商品数量
}
}
}else {
JOptionPane.showMessageDialog(null,"您 输 入 的 商 品 序 号 不 存 在 !", "错误",JOptionPane.ERROR_MESSAGE);
field.setText("");
field1.setText("");
}
}

}

}
package com.shop.JFrame;
/***管理员服务选择界面***/


public class AdminSelect extends JFrame {

private final JPanel contenctPanel = new JPanel();

private final JButton button1 = new JButton();
private final JButton button2 = new JButton();
private final JButton button3 = new JButton();
private final JButton button4 = new JButton();
private final JButton button5 = new JButton();
private final JButton button6 = new JButton();
private final JButton button7 = new JButton();

private final JLabel label = new JLabel();//文本标签
private final JLabel label0 = new JLabel();//文本标签
private final JLabel label1 = new JLabel();//文本标签
private final JLabel label2 = new JLabel();//文本标签

private final Box base = Box.createVerticalBox();
private final Box box = Box.createHorizontalBox();
private final Box box0 = Box.createHorizontalBox();
private final Box box1 = Box.createHorizontalBox();
private final Box box2 = Box.createHorizontalBox();
private final Box box3 = Box.createHorizontalBox();
private final Box box4 = Box.createHorizontalBox();
private final Box box5 = Box.createHorizontalBox();
private final Box box6 = Box.createHorizontalBox();


项目链接:
https://javayms.github.io?id=292121051901101aa
https://javayms.pages.dev?id=292121051901101aa