基于Mysql+JavaSwing的超市商品管理系統(tǒng)設(shè)計與實現(xiàn)
:
隨著小超市規(guī)模的發(fā)展不斷擴大, 商品數(shù)量急劇增加, 有關(guān)商品的各種信息量也成倍增長。 超市時時刻刻都需要對商品各種信息進行統(tǒng)計分析。 而大型的超市管理系統(tǒng)功能過于強大而造成操作繁瑣降低了小超市的工作效率。 超市管理系統(tǒng)是市場上最流行的超市上常用的系統(tǒng)之一, 由于剛學(xué)Java知識、所有功能設(shè)計的比較簡單、只有商品信息的增刪改查。實現(xiàn)對商品信息全面、 動態(tài)、及時的管理。本文系統(tǒng)的分析了軟件開發(fā)的背景以過程;首先介紹了軟件的開發(fā)環(huán)境, 其次介紹了本軟件的詳細(xì)設(shè)計過程: 數(shù)據(jù)庫的設(shè)計、各個模塊的設(shè)計和實現(xiàn),以及具體界面的設(shè)計和功能。超市庫存管理系統(tǒng)是基于 Java eclipse 作為開發(fā)工具 , Mysql 作為后臺數(shù)據(jù)庫支持。超市庫存管理系統(tǒng)開發(fā)主要是界面程序的開發(fā)、數(shù)據(jù)庫的建立、數(shù)據(jù)庫的維護。應(yīng)用程序功能完善,界面人機交互要好,而且操作簡單。同時 JAVASwing語言簡單,在較短的時間內(nèi)能夠開發(fā)出使用性強、 功能完善, 易于操作的程序, 也能實現(xiàn)與數(shù)據(jù)庫的連接。
主要模塊:
商品列表數(shù)據(jù)展示、商品信息添加、商品信息修改、商品信息刪除、按照商品名稱查詢商品信息
1、功能介紹
功能截圖:
查詢商品列表信息:
添加商品信息:
修改商品信息:
刪除商品信息:
刪除之后需要刷新一下列表數(shù)據(jù)
編號查詢商品信息:
2、關(guān)鍵代碼
2.1 主頁功能
public class GoodsManage extends JFrame { private JTextField textField; Select select = new Select(); Updata updata = new Updata(); Object[] header= {"商品編號","商品名稱","數(shù)量","單價"}; 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("商品管理系統(tǒng)"); 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, "請選擇要修改的數(shù)據(jù)!"); } 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, "請選中要刪除的數(shù)據(jù)!"); } 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("商品管理系統(tǒng)"); 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("數(shù)量:"); 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, "請完整輸入要添加的數(shù)據(jù)"); } 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 數(shù)據(jù)庫設(shè)計
商品表
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 ;
到此這篇關(guān)于基于Mysql+JavaSwing
的超市商品管理系統(tǒng)設(shè)計與實現(xiàn)的文章就介紹到這了,更多相關(guān)Mysql+JavaSwing
的超市商品管理系統(tǒng)設(shè)計與實現(xiàn)內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。