基于java+mysql的swing+mysql电子商城(java+swing+mysql+gui)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
管理员管理商品、用户购买商品等
eclipse运行:
idea运行:
前台用户:
后台管理员:
技术框架
Java Swing GUI
基于java+mysql的Swing+MySQL电子商城(java+swing+mysql+gui)
//返回商城主界面
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();
}
}
});
box.add(label);
box0.add(label0);
box1.add(label1);
box1.add(field);
box2.add(label2);
box2.add(password1);
box3.add(label3);
box3.add(field2);
box4.add(button);
box4.add(button1);
base.add(box);
base.add(Box.createVerticalStrut(40));
base.add(box0);
base.add(Box.createVerticalStrut(40));
base.add(box1);
base.add(Box.createVerticalStrut(30));
base.add(box2);
base.add(Box.createVerticalStrut(30));
base.add(box3);
base.add(Box.createVerticalStrut(50));
base.add(box4);
button6.setBorderPainted(false);
button6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == button6) {
dispose();
AdminGoodsUpdate update = new AdminGoodsUpdate(adminname);
update.getName(adminname);
}
}
});
button7.setText("7、退出 管理员 登录");
button7.setBackground(Color.WHITE);
button7.setFont(new Font("微软雅黑",1,18));
button7.setBorderPainted(false);
button7.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == button7) {
OptionPane option = new OptionPane();
dispose();
}
}
});
box.add(label);
box0.add(label0);
box9.add(label1);
box1.add(button1);
box2.add(button2);
box3.add(button3);
box4.add(button4);
box5.add(button5);
box6.add(button6);
box7.add(button7);
base.add(box);
base.add(Box.createVerticalStrut(40));
base.add(box0);
base.add(Box.createVerticalStrut(40));
base.add(box9);
base.add(Box.createVerticalStrut(40));
base.add(box1);
base.add(Box.createVerticalStrut(40));
base.add(box2);
base.add(Box.createVerticalStrut(40));
base.add(box3);
label2.setText("尊敬的 "+username+" VIP用户,这是您所有的购买记录!");
label2.setFont(new Font("微软雅黑",0,18));
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();
UserSelect select = new UserSelect(username);
select.getName(username);
}
}
});
box.add(label);
box1.add(label0);
box2.add(label1);
box3.add(scroll);
box4.add(label2);
box5.add(button);
box5.add(button1);
base.add(box);
base.add(Box.createVerticalStrut(20));
base.add(box1);
base.add(Box.createVerticalStrut(20));
base.add(box2);
base.add(Box.createVerticalStrut(20));
base.add(box3);
base.add(Box.createVerticalStrut(20));
base.add(box4);
base.add(Box.createVerticalStrut(30));
base.add(box5);
base.add(Box.createVerticalStrut(40));
contenctPanel.add(base);
add(contenctPanel);
JOptionPane.showMessageDialog(null,"添加商品成功!","正确", JOptionPane.DEFAULT_OPTION);
}
}
}
}
package com.shop.JFrame;
/***用户找回密码和账户界面***/
public class UserSearch extends JFrame {
String useremail, card, username, password;
private final JPanel contenctPanel = new JPanel();
private final JTextField field = new JTextField(20);
private final JTextField field1 = new JTextField(20);
private final JTextField field2 = new JTextField(20);
private final JLabel label = 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 box5 = Box.createHorizontalBox();
private final Box box1 = Box.createHorizontalBox();
private final Box box2 = Box.createHorizontalBox();
private final Box box3 = Box.createHorizontalBox();
if(decideUsercard(card,useremail) == false) {
JOptionPane.showMessageDialog(null,"未找到该用户,请重新输入!", "错误",JOptionPane.ERROR_MESSAGE);
}else if(decideUsercard(card,useremail) == true){
String option = "您的用户名是:"+username+"\n"+"您的密码是:"+password+"\n";
JOptionPane.showMessageDialog(null, option, "查找结果",JOptionPane.CLOSED_OPTION);
}
}
}
public boolean decideUsercard(String usercard, String useremail){
Util db = new Util();
conn = db.getConnection();
try{
pres = conn.prepareStatement("select userName, userCard, userPass, userEmail from user where userCard = ? and userEmail = ?");
pres.setString(1, usercard);
pres.setString(2, useremail);
res = pres.executeQuery();
while(res.next()){
String card = res.getString("userCard");
String name = res.getString("userName");
String pass = res.getString("userPass");
String email = res.getString("userEmail");
if(card.equals(usercard) && email.equals(useremail)){
username = name;
password = pass;
return true;
}
}
res.close();
pres.close();
conn.close();
}catch(Exception e){
e.printStackTrace();
}
return false;
}
}
package com.shop.JFrame;
/***管理员登录界面***/
public class AdminLogin extends JFrame {
box1.add(label0);
box2.add(label1);
box3.add(scroll);
box4.add(label2);
box5.add(button);
box5.add(button1);
base.add(box);
base.add(Box.createVerticalStrut(20));
base.add(box1);
base.add(Box.createVerticalStrut(20));
base.add(box2);
base.add(Box.createVerticalStrut(20));
base.add(box3);
base.add(Box.createVerticalStrut(20));
base.add(box4);
base.add(Box.createVerticalStrut(30));
base.add(box5);
base.add(Box.createVerticalStrut(40));
contenctPanel.add(base);
add(contenctPanel);
setVisible(true);
}
class Myaction extends JFrame implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
DBcostDel costdel = new DBcostDel();
costdel.Costdel(username);
JOptionPane.showMessageDialog(null, "清 空 购 物 车 !", "成功",JOptionPane.DEFAULT_OPTION);
}
}
}
package com.shop.JFrame;
/***用户选择界面***/
}
}
}
package com.shop.JFrame;
/***管理员修改商品信息界面***/
public class AdminGoodsUpdate extends JFrame {
static Connection conn; //声明Connection对象
static PreparedStatement pres; //向数据库发送SQL语句
static ResultSet res; //执行数据库查询
private String adminname;
private final JPanel contenctPanel = new JPanel();
private final JTextField field = new JTextField(10);
private final JTextField field1 = new JTextField(10);
private final JTextField field2 = new JTextField(10);
private final JTextField field3 = new JTextField(10);
private final JTextField field4 = new JTextField(10);
private final JTextField field5 = new JTextField(10);
//private final JPasswordField password = new JPasswordField();//密码文本框
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 JLabel label5 = new JLabel();
private final JLabel label6 = new JLabel();
private final JLabel label7 = new JLabel();
private final JLabel label8 = 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 box0 = Box.createHorizontalBox();
private final Box box1 = Box.createHorizontalBox();
private final Box box2 = Box.createHorizontalBox();
private final Box box3 = Box.createHorizontalBox();
box3.add(button1);
base.add(box);
base.add(Box.createVerticalStrut(40));
base.add(box0);
base.add(Box.createVerticalStrut(20));
base.add(box1);
base.add(Box.createVerticalStrut(30));
base.add(box2);
base.add(Box.createVerticalStrut(30));
base.add(box3);
base.add(Box.createVerticalStrut(30));
contenctPanel.add(base);
add(contenctPanel);
setVisible(true);
}
}
package com.shop.JFrame;
/***查看商城商品信息界面***/
public class GoodsLook extends JFrame {
static Connection conn; //声明Connection对象
static PreparedStatement pres; //向数据库发送SQL语句
static ResultSet res; //执行数据库查询
private final JPanel contenctPanel = new JPanel();
//private final JPasswordField password = new JPasswordField();//密码文本框
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 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();
package com.shop.JFrame;
/***管理员查看用户信息界面***/
public class AdminUserLook extends JFrame {
private String adminname;
static Connection conn; //声明Connection对象
static PreparedStatement pres; //向数据库发送SQL语句
static ResultSet res; //执行数据库查询
private final JPanel contenctPanel = new JPanel();
//private final JPasswordField password = new JPasswordField();//密码文本框
private final JLabel label = new JLabel();
private final JLabel label0 = new JLabel();
private final JLabel label1 = 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 box0 = Box.createHorizontalBox();
private final Box box1 = Box.createHorizontalBox();
private final Box box2 = Box.createHorizontalBox();
private final Box box3 = Box.createHorizontalBox();
private JTextArea text= new JTextArea();
public void getName(String name) {
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、退出 在线 电子商城");
button7.setBackground(Color.WHITE);
button7.setFont(new Font("微软雅黑",0,18));
button7.setBorderPainted(false);
box8.add(label);
box9.add(label1);
box1.add(button1);
box1.add(Box.createVerticalStrut(40));
box2.add(button2);
box2.add(Box.createVerticalStrut(40));
box3.add(button3);
box3.add(Box.createVerticalStrut(40));
box4.add(button4);
box4.add(Box.createVerticalStrut(40));
box5.add(button5);
box5.add(Box.createVerticalStrut(40));
box6.add(button6);
box6.add(Box.createVerticalStrut(40));
box7.add(button7);
box7.add(Box.createVerticalStrut(40));
base.add(box8);
base.add(Box.createVerticalStrut(40));
base.add(box9);
base.add(Box.createVerticalStrut(40));
private String adminname;
private final JPanel contenctPanel = new JPanel();
private final JTextField field = new JTextField(10);
private final JTextField field1 = new JTextField(10);
private final JTextField field2 = new JTextField(10);
private final JTextField field3 = new JTextField(10);
private final JTextField field4 = new JTextField(10);
private final JTextField field5 = new JTextField(10);
//private final JPasswordField password = new JPasswordField();//密码文本框
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 JLabel label5 = new JLabel();
private final JLabel label6 = new JLabel();
private final JLabel label7 = new JLabel();
private final JLabel label8 = 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 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();
private final Box box7 = Box.createHorizontalBox();
private final Box box8 = Box.createHorizontalBox();
private final Box box9 = Box.createHorizontalBox();
private final Box box10 = Box.createHorizontalBox();
private final Box box11 = Box.createHorizontalBox();
private JTextArea text= new JTextArea();
public void getName(String name) {
this.adminname = name;
}
public AdminGoodsUpdate(String adminname) {
setTitle("欢迎使用 在线 电子商城");
setBounds(300,100,900,900);
setVisible(true);
res = pres.executeQuery(); //执行查询语句
text.setText("----用 户 序 号-----"+"---用 户 名------"+"-------用 户 密 码------"+"-------用 户 身 份 证 号-----------"+"--用 户 年 龄------"+"--用 户 邮 箱-----------"+"--用 户 地 址----");
while(res.next()){
int id = res.getInt("userId");
String name = res.getString("userName");
String pass = res.getString("userPass");
String card = res.getString("userCard");
int age = res.getInt("userAge");
String email = res.getString("userEmail");
String address = res.getString("userAddress");
text.append("\n"+" "+id+" \t "+name+"\t "+pass+" "+card+"\t "+age+" \t "+email+" "+address+"\n");
}
res.close();
pres.close();
conn.close();
}catch(Exception e) {
e.printStackTrace();
}
JScrollPane scroll = new JScrollPane(text);
scroll.setSize(700, 700);
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) {
AdminSelect select = new AdminSelect(adminname);
select.getName(adminname);
dispose();
}
}
});
box.add(label);
box0.add(label0);
box1.add(label1);
box2.add(scroll);
box3.add(button1);
base.add(box);
base.add(Box.createVerticalStrut(40));
base.add(box0);
base.add(Box.createVerticalStrut(20));
base.add(box1);
base.add(Box.createVerticalStrut(30));
base.add(box2);
base.add(Box.createVerticalStrut(30));
base.add(box3);
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 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();
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);
base.add(Box.createVerticalStrut(30));
base.add(box2);
base.add(Box.createVerticalStrut(30));
base.add(box3);
base.add(Box.createVerticalStrut(50));
base.add(box4);
base.add(Box.createVerticalStrut(50));
contenctPanel.add(base);
add(contenctPanel);
}
class Myaction extends JFrame implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
DBadminPassdecide passdecide = new DBadminPassdecide();
DBadminNamedecide namedecide = new DBadminNamedecide();
if(e.getSource() == button) {
//获取文本框输入的信息
username = field.getText();
password = password1.getText();
String option =username + " 用户恭喜您注册成功";
//判断用户名、密码
if(namedecide.decideAdminname(username) == false) {
JOptionPane.showMessageDialog(null,"用户不存在,请重新输入!", "错误",JOptionPane.ERROR_MESSAGE);
field.setText("");
}else if(passdecide.decideAdminpass(username, password) == false) {
JOptionPane.showMessageDialog(null,"密码不正确,请重新输入!", "错误",JOptionPane.ERROR_MESSAGE);
field1.setText("");
}else{
dispose();
AdminSelect select = new AdminSelect(username);//跳转到管理员服务选择界面
select.getName(username);
}
}
}
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();
private JTextArea text= new JTextArea();
private String username;
public void getName(String name) {
this.username = name;
}
public UserBuy(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");
text.setSize(800, 800);
Util db = new Util();
conn = db.getConnection();
try {
pres = conn.prepareStatement("select * from user");
res = pres.executeQuery(); //执行查询语句
text.setText("----用 户 序 号-----"+"---用 户 名------"+"-------用 户 密 码------"+"-------用 户 身 份 证 号-----------"+"--用 户 年 龄------"+"--用 户 邮 箱-----------"+"--用 户 地 址----");
while(res.next()){
int id = res.getInt("userId");
String name = res.getString("userName");
String pass = res.getString("userPass");
String card = res.getString("userCard");
int age = res.getInt("userAge");
String email = res.getString("userEmail");
String address = res.getString("userAddress");
text.append("\n"+" "+id+" \t "+name+"\t "+pass+" "+card+"\t "+age+" \t "+email+" "+address+"\n");
}
res.close();
pres.close();
conn.close();
}catch(Exception e) {
e.printStackTrace();
}
JScrollPane scroll = new JScrollPane(text);
scroll.setSize(700, 700);
label2.setText("这是所有的用户信息,删除用户只需要输入用户序号!");
label2.setFont(new Font("微软雅黑",0,18));
label3.setText("请 输 入 要 删 除 用 户 的 序 号:");
label3.setFont(new Font("微软雅黑",0,18));
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();
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("");
}
}
}
});
//登录按钮
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();
}
}
});
box.add(label);
box0.add(label0);
box1.add(label1);
box1.add(field);
box2.add(label2);
base.add(box7);
base.add(Box.createVerticalStrut(40));
contenctPanel.add(base);
add(contenctPanel);
/***用户注册***/
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() {
box5.add(Box.createVerticalStrut(40));
box6.add(button6);
box6.add(Box.createVerticalStrut(40));
box7.add(button7);
box7.add(Box.createVerticalStrut(40));
base.add(box8);
base.add(Box.createVerticalStrut(40));
base.add(box9);
base.add(Box.createVerticalStrut(40));
base.add(box1);
base.add(Box.createVerticalStrut(40));
base.add(box2);
base.add(Box.createVerticalStrut(40));
base.add(box3);
base.add(Box.createVerticalStrut(40));
base.add(box4);
base.add(Box.createVerticalStrut(40));
base.add(box5);
base.add(Box.createVerticalStrut(40));
base.add(box6);
base.add(Box.createVerticalStrut(40));
base.add(box7);
base.add(Box.createVerticalStrut(40));
contenctPanel.add(base);
add(contenctPanel);
/***用户注册***/
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == button1) {
dispose();//销毁窗体
UserRegion region = new UserRegion();
}
}
});
base.add(box6);
base.add(Box.createVerticalStrut(40));
base.add(box7);
base.add(Box.createVerticalStrut(40));
contenctPanel.add(base);
add(contenctPanel);
}
class Myaction extends JFrame implements ActionListener{
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
DBgoodsNamedecide decide = new DBgoodsNamedecide();
DBgoodsInsert insert = new DBgoodsInsert();
String name = field.getText();
String date = field1.getText();
BigDecimal vip = BigDecimal.valueOf(Double.parseDouble(field2.getText()));
BigDecimal money = BigDecimal.valueOf(Double.parseDouble(field3.getText()));
int num = Integer.parseInt(field4.getText());
if(decide.decideGoodsname(name)) {
JOptionPane.showMessageDialog(null,"商品名不能重复!", "错误",JOptionPane.ERROR_MESSAGE);
field.setText("");
}else if(insert.Goodsinsert(name, date, vip, money, num)){
JOptionPane.showMessageDialog(null,"添加商品成功!","正确", JOptionPane.DEFAULT_OPTION);
}
}
}
}
package com.shop.JFrame;
/***用户找回密码和账户界面***/
public class UserSearch extends JFrame {
String useremail, card, username, password;
private final JPanel contenctPanel = new JPanel();
//用户名
label2.setText("用户名(字母和数字组成,至少为6位):");
label2.setFont(new Font("微软雅黑",0,18));
field.addActionListener(new Myaction());
//密码
label3.setText("密 码(字母 和 数字 组成,至少为6位):");
label3.setFont(new Font("微软雅黑",0,18));
field1.addActionListener(new Myaction());
password1.setText(password);
//随机验证码
Rand rand= new Rand();
int num = rand.getRandom();
label4.setText("请 输 入 随 机 验 证 码 ( "+ num +" ):");
label4.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("");
}
}
}
});
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) {
AdminSelect select = new AdminSelect(adminname);
select.getName(adminname);
dispose();
}
}
scroll.setSize(800, 800);
label2.setText("这是所有的商品信息!");
label2.setFont(new Font("微软雅黑",0,18));
label3.setText("请输 入 要 修 改 的 商 品 序 号:");
label3.setFont(new Font("微软雅黑",0,18));
label4.setText("请 输 入 要 新 的 商 品 名 称:");
label4.setFont(new Font("微软雅黑",0,18));
label5.setText("请 输 入 要 新 的 生 产 日 期:");
label5.setFont(new Font("微软雅黑",0,18));
label6.setText("请 输 入 要 新 的 会 员 价 格:");
label6.setFont(new Font("微软雅黑",0,18));
label7.setText("请 输 入 要 新 的 非 会员价格:");
label7.setFont(new Font("微软雅黑",0,18));
label8.setText("请 输 入 要 新 的 商 品 数 量:");
label8.setFont(new Font("微软雅黑",0,18));
button.setText("立 即 修 改");
button.setFont(new Font("微软雅黑",1,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();
AdminSelect select = new AdminSelect(adminname);
select.getName(adminname);
}
}
});
box.add(label);
box1.add(label0);
box2.add(label1);
box3.add(scroll);
box4.add(label2);
box5.add(label3);
out.print("\n\t\t您输入新的的商品非会员价格:");
BigDecimal money = cin.nextBigDecimal();
up.setupgoodsMoney(goodsid, money);
AdminUpdategoods update = new AdminUpdategoods();
update.back();
break;
}case 5:{
out.print("\n\t\t您输入新的的商品数量:");
int num = cin.nextInt();
up.setupgoodsNum(goodsid, num);
AdminUpdategoods update = new AdminUpdategoods();
update.back();
break;
}default:{
out.println("\n\t\t您的输入有误!");
break;
}
}
}
public void back() {
Timewait wait = new Timewait();
AdminUpdategoods up = new AdminUpdategoods();
out.println("\n\t\t修改成功!");
out.print("\n\n\t\t请问您是否还要继续删除(输入 Y/y 继续执行操作,否则返回管理员主界面):");
String str = cin.next();
if(str.equals("Y") || str.equals("y")) {
wait.wait500();
up.Updategoods();
}else {
out.println("\n\n\t\t即将返回管理员主界面,请稍后!\n");
wait.wait1000();
AdminWelcome welcome = new AdminWelcome();
welcome.getWelcome();
}
}
}
package com.shop.user;
/***用户注册界面***/
label5.setText("商 品 数 量:");
label5.setFont(new Font("微软雅黑",0,18));
field4.addActionListener(new Myaction());
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();
AdminSelect select = new AdminSelect(adminname);
select.getName(adminname);
}
}
});
box.add(label);
box0.add(label0);
box1.add(label6);
box2.add(label1);
box2.add(field);
box3.add(label2);
box3.add(field1);
box4.add(label3);
box4.add(field2);
box5.add(label4);
box5.add(field3);
box6.add(label5);
box6.add(field4);
box7.add(button);
box7.add(button1);
base.add(box);
base.add(Box.createVerticalStrut(40));
base.add(box0);
base.add(Box.createVerticalStrut(20));
base.add(box1);
base.add(Box.createVerticalStrut(30));
base.add(box2);
base.add(Box.createVerticalStrut(30));
base.add(box3);
base.add(Box.createVerticalStrut(30));
base.add(box4);
base.add(Box.createVerticalStrut(30));
base.add(box5);
base.add(box);
base.add(Box.createVerticalStrut(20));
base.add(box1);
base.add(Box.createVerticalStrut(20));
base.add(box2);
base.add(Box.createVerticalStrut(20));
base.add(box3);
base.add(Box.createVerticalStrut(20));
base.add(box4);
base.add(Box.createVerticalStrut(30));
base.add(box5);
base.add(Box.createVerticalStrut(40));
base.add(box6);
base.add(Box.createVerticalStrut(40));
base.add(box7);
base.add(Box.createVerticalStrut(40));
contenctPanel.add(base);
add(contenctPanel);
setVisible(true);
}
class Myaction extends JFrame implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
DBgoodsId goodsid = new DBgoodsId();
DBgoodsName goodsname = new DBgoodsName();
DBgoodsVIPmoney money = new DBgoodsVIPmoney();
DBgoodsNum goodsnum = new DBgoodsNum();
DBcostInsert insert = new DBcostInsert();
DBgoodsUP update = new DBgoodsUP();
int id = Integer.parseInt(field.getText());
int num = Integer.parseInt(field1.getText());
if(goodsid.getgoodsID(id) == id) {
int n = goodsnum.getgoodsNum(id);
if(num > n || num == 0) {
JOptionPane.showMessageDialog(null,"您 购 买 的 商 品 库 存 不 足 !", "错误",JOptionPane.ERROR_MESSAGE);
field.setText("");
field1.setText("");
}else {
String name = goodsname.getgoodsName(id);//获取商品名称