基于JavaSwing+Mysql的超市商品管理系统设计

私信获取完整代码

    本项目是使用Java swing开发,可实现超市管理系统商品列表信息查询、添加商品信息和修改商品管理以及删除商品信息和安装商品信息查询等功能。界面设计和功能比较简单基础、适合作为Java课设设计以及学习技术使用。

摘要:

      随着小超市规模的发展不断扩大, 商品数量急剧增加, 有关商品的各种信息量也成倍增长。 超市时时刻刻都需要对商品各种信息进行统计分析。 而大型的超市管理系统功能过于强大而造成操作繁琐降低了小超市的工作效率。 超市管理系统是市场上最流行的超市上常用的系统之一, 由于刚学Java知识、所有功能设计的比较简单、只有商品信息的增删改查。实现对商品信息全面、 动态、及时的管理。本文系统的分析了软件开发的背景以过程;首先介绍了软件的开发环境, 其次介绍了本软件的详细设计过程: 数据库的设计、各个模块的设计和实现,以及具体界面的设计和功能。超市库存管理系统是基于 Java eclipse 作为开发工具 , Mysql 作为后台数据库支持。超市库存管理系统开发主要是界面程序的开发、数据库的建立、数据库的维护。应用程序功能完善,界面人机交互要好,而且操作简单。同时 JAVASwing语言简单,在较短的时间内能够开发出使用性强、 功能完善, 易于操作的程序, 也能实现与数据库的连接。

主要模块:

商品列表数据展示、商品信息添加、商品信息修改、商品信息删除、按照商品名称查询商品信息

功能截图:

查询商品列表信息

添加商品信息:

修改商品信息:

删除商品信息:

删除之后需要刷新一下列表数据

编号查询商品信息:

部分关键代码:

主页功能:

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);
	}
}

添加商品信息:

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();
			}
		});
		
	}
}

数据库设计:

商品表:

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
;

备注:项目来于网络、作者整理优化测试编写文档、若有侵权联系删除

总结: 

         通过这次课程设计。我学到了许多令我受益匪浅的知识。感觉java的界面设计和 mfc差不多。只是java没有可视化的界面做起来太累了。其他主要是类和对象的问题。实现起来还是挺简单的。综合了根据超市系统的实际情况的特点, 虽然用户界面和功能设计比较一般,但操作使用还是方便。满足学生学习的一个基本状态。了解Java对象和swing窗口化图形化编程的特性、由于时间仓促,只做了商品的CRUD、需要其他功能的可以自行设计和添加上、作为学生学习参考以及课程设计还是不错的选择。 

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

进击的代码家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值