基于Mysql+JavaSwing的超市商品管理系统设计与实现
作者:java李杨勇 时间:2024-01-29 00:31:46
目录
1、功能介绍
2、关键代码
2.1 主页功能
2.2 添加商品信息
2.3 数据库设计
商品表
前言:
随着小超市规模的发展不断扩大, 商品数量急剧增加, 有关商品的各种信息量也成倍增长。 超市时时刻刻都需要对商品各种信息进行统计分析。 而大型的超市管理系统功能过于强大而造成操作繁琐降低了小超市的工作效率。 超市管理系统是市场上最流行的超市上常用的系统之一, 由于刚学Java知识、所有功能设计的比较简单、只有商品信息的增删改查。实现对商品信息全面、 动态、及时的管理。本文系统的分析了软件开发的背景以过程;首先介绍了软件的开发环境, 其次介绍了本软件的详细设计过程: 数据库的设计、各个模块的设计和实现,以及具体界面的设计和功能。超市库存管理系统是基于 Java eclipse 作为开发工具 , Mysql 作为后台数据库支持。超市库存管理系统开发主要是界面程序的开发、数据库的建立、数据库的维护。应用程序功能完善,界面人机交互要好,而且操作简单。同时 JAVASwing语言简单,在较短的时间内能够开发出使用性强、 功能完善, 易于操作的程序, 也能实现与数据库的连接。
主要模块:
商品列表数据展示、商品信息添加、商品信息修改、商品信息删除、按照商品名称查询商品信息
1、功能介绍
功能截图:
查询商品列表信息:
添加商品信息:
修改商品信息:
删除商品信息:
删除之后需要刷新一下列表数据
编号查询商品信息:
2、关键代码
2.1 主页功能
public class GoodsManage extends JFrame {
private JTextField textField;
Select select = new Select();
Updata updata = new Updata();
Object[] header= {"商品编号","商品名称","数量","单价"};
String sql = "SELECT goodsID,goodsname,num,price FROM goods";
Object[][] data= select.getGoods(sql);
DefaultTableModel df = new DefaultTableModel(data, header);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
public GoodsManage() {
super("商品管理系统");
this.setBounds(0, 0, 700, 450);
this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
this.setResizable(false);//让窗口大小不可改变
getContentPane().setLayout(null);
JTable jTable = new JTable(df);
JScrollPane jsp=new JScrollPane(jTable,v,h);
jsp.setBounds(10, 10, 515, 320);
getContentPane().add(jsp);
JButton button_1 = new JButton("显示所有商品");
button_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String sql = "SELECT goodsID,goodsname,num,price FROM goods";
Object[][] data = Select.getGoods(sql);
df.setDataVector(data, header);
}
});
button_1.setBounds(535, 80, 127, 30);
getContentPane().add(button_1);
JButton button_2 = new JButton("修改商品");
button_2.setBounds(535, 140, 127, 30);
getContentPane().add(button_2);
button_2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jTable.getSelectedColumn()<0) {
JOptionPane.showMessageDialog(null, "请选择要修改的数据!");
} else {
int goodsID = Integer.parseInt(jTable.getValueAt(jTable.getSelectedRow(), 0).toString());
String name = jTable.getValueAt(jTable.getSelectedRow(), 1).toString();
int num = Integer.parseInt(jTable.getValueAt(jTable.getSelectedRow(), 2).toString());
String price = jTable.getValueAt(jTable.getSelectedRow(), 3).toString();
Goods goods = new Goods(goodsID,name,num,price);
GoodsXG goodsXG = new GoodsXG(goods);
goodsXG.setVisible(true);
}
}
});
JButton button_3 = new JButton("删除商品");
button_3.setBounds(535, 200, 127, 30);
getContentPane().add(button_3);
button_3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jTable.getSelectedColumn()<0) {
JOptionPane.showMessageDialog(null, "请选中要删除的数据!");
} else {
int goodsID = Integer.parseInt(jTable.getValueAt(jTable.getSelectedRow(), 0).toString());
String sql="delete from goods where goodsid="+goodsID;
int result = updata.addData(sql);
if (result>0) {
JOptionPane.showMessageDialog(null, "删除成功!");
JOptionPane.showMessageDialog(null, "记得刷新一下哦!");
} else {
JOptionPane.showMessageDialog(null, "删除失败!");
}
}
}
});
JButton button_4 = new JButton("添加商品");
button_4.setBounds(535, 258, 127, 30);
getContentPane().add(button_4);
button_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
GoodsADD goodsAdd = new GoodsADD();
goodsAdd.setVisible(true);
}
});
JLabel label = new JLabel("商品编号:");
label.setBounds(40, 354, 112, 32);
getContentPane().add(label);
textField = new JTextField();
textField.setBounds(154, 358, 127, 26);
getContentPane().add(textField);
textField.setColumns(10);
JButton button = new JButton("按编号查询");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String sql = "SELECT goodsID,goodsname,num,price FROM goods WHERE goodsid LIKE '%"+textField.getText()+"%'";
Object[][] data = Select.getGoods(sql);
df.setDataVector(data, header);
}
});
button.setBounds(305, 355, 112, 30);
getContentPane().add(button);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
//加入动作
GoodsManagement m = new GoodsManagement();
m.setVisible(true);
}
});
}
public static void main(String[] args) {
GoodsManage t = new GoodsManage();
t.setVisible(true);
}
}
2.2 添加商品信息
public class GoodsADD extends JFrame {
private JTextField id,name,num,price;
private JButton button;
private JButton button_1;
public GoodsADD() {
super("商品管理系统");
this.setBounds(0, 0, 400, 450);
this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
this.setResizable(false);//让窗口大小不可改变
getContentPane().setLayout(null);
JLabel label = new JLabel("商品编号:");
label.setBounds(85, 89, 87, 22);
getContentPane().add(label);
id = new JTextField();
id.setBounds(147, 90, 142, 21);
getContentPane().add(id);
id.setColumns(10);
JLabel label_1 = new JLabel("商品名称");
label_1.setBounds(85, 139, 87, 22);
getContentPane().add(label_1);
name = new JTextField();
name.setColumns(10);
name.setBounds(147, 140, 142, 21);
getContentPane().add(name);
JLabel label_2 = new JLabel("数量:");
label_2.setBounds(85, 193, 87, 22);
getContentPane().add(label_2);
num = new JTextField();
num.setColumns(10);
num.setBounds(147, 194, 142, 21);
getContentPane().add(num);
JLabel label_3 = new JLabel("单价:");
label_3.setBounds(85, 241, 87, 22);
getContentPane().add(label_3);
price = new JTextField();
price.setColumns(10);
price.setBounds(147, 242, 142, 21);
getContentPane().add(price);
button = new JButton("确定");
button.setBounds(78, 317, 93, 23);
getContentPane().add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String addId = id.getText();
String addName = name.getText();
String addNum = num.getText();
String addPrice = num.getText();
if (addName.equals("")||addName.equals("")||addNum.equals("")||addPrice.equals("")) {
JOptionPane.showMessageDialog(null, "请完整输入要添加的数据");
} else {
String sql="INSERT INTO goods VALUES("+addId+",'"+addName+"','"+addNum+"','"+addPrice+"')";
int result = Updata.addData(sql);
if (result>0) {
JOptionPane.showMessageDialog(null, "添加成功!");
JOptionPane.showMessageDialog(null, "记得刷新一下哦!");
dispose();
// GoodsManage i = new GoodsManage();
// i.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "添加失败!");
}
}
}
});
button_1 = new JButton("取消");
button_1.setBounds(208, 317, 93, 23);
getContentPane().add(button_1);
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
dispose();
}
});
}
}
2.3 数据库设计
商品表
CREATE TABLE `NewTable` (
`goodsID` int(11) NOT NULL ,
`goodsName` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`num` int(11) NOT NULL ,
`price` decimal(10,4) NOT NULL ,
PRIMARY KEY (`goodsID`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
ROW_FORMAT=COMPACT
;
来源:https://juejin.cn/post/7012021268597702664
标签:Mysql,JavaSwing
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
在ASP.NET 2.0中操作数据之六十七:在TableAdapters中使用JOINs
2024-05-11 09:26:35
![](https://img.aspxhome.com/file/2023/3/126203_0s.png)
Mysql join联表及id自增实例解析
2024-01-22 20:36:20
![](https://img.aspxhome.com/file/2023/0/126260_0s.png)
MySQL绿色解压缩版安装与配置操作步骤
2024-01-14 07:00:15
Servermanager启动连接数据库错误如何解决
2024-01-13 23:46:55
![](https://img.aspxhome.com/file/2023/9/121299_0s.png)
js中各浏览器中鼠标按键值的差异
2024-05-05 09:15:28
![](https://img.aspxhome.com/file/2023/8/129568_0s.png)
DIV+CSS设计时容易犯的一些错误
2007-11-13 12:42:00
javascript 选择文件夹对话框(web)
2024-04-17 09:48:43
![](https://img.aspxhome.com/file/2023/4/136534_0s.png)
python 爬虫 实现增量去重和定时爬取实例
2022-01-26 01:01:37
Django自定义分页效果
2023-12-06 00:09:04
![](https://img.aspxhome.com/file/2023/1/84001_0s.png)
详解mysql中的存储引擎
2024-01-27 05:53:15
![](https://img.aspxhome.com/file/2023/2/71792_0s.png)
Golang远程调用框架RPC的具体使用
2024-02-16 01:50:02
Navicat Premium15连接云服务器中的数据库问题及遇到坑
2024-01-19 05:41:50
![](https://img.aspxhome.com/file/2023/2/77212_0s.png)
python数据可视化matplotlib绘制折线图示例
2023-05-20 23:01:56
![](https://img.aspxhome.com/file/2023/9/103159_0s.png)
Python实现常见坐标系的相互转换
2021-11-15 18:32:48
![](https://img.aspxhome.com/file/2023/4/120454_0s.png)
Python3如何使用tabulate打印数据
2021-04-17 15:09:26
![](https://img.aspxhome.com/file/2023/7/124137_0s.png)
完美卸载Oracle数据库
2024-01-18 02:50:27
![](https://img.aspxhome.com/file/2023/2/64852_0s.png)
Python游戏推箱子的实现
2023-09-23 05:31:27
![](https://img.aspxhome.com/file/2023/9/70759_0s.jpg)
python中asyncore异步模块的实现
2023-10-23 00:50:07
浅谈python中对于json写入txt文件的编码问题
2022-01-28 05:08:58
Python中pycharm编辑器界面风格修改方法
2023-11-04 08:43:42
![](https://img.aspxhome.com/file/2023/3/75263_0s.jpg)