基于Mysql+JavaSwing的超市商品管理系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)
前言:
隨著小超市規(guī)模的發(fā)展不斷擴(kuò)大, 商品數(shù)量急劇增加, 有關(guān)商品的各種信息量也成倍增長(zhǎng)。 超市時(shí)時(shí)刻刻都需要對(duì)商品各種信息進(jìn)行統(tǒng)計(jì)分析。 而大型的超市管理系統(tǒng)功能過(guò)于強(qiáng)大而造成操作繁瑣降低了小超市的工作效率。 超市管理系統(tǒng)是市場(chǎng)上最流行的超市上常用的系統(tǒng)之一, 由于剛學(xué)Java知識(shí)、所有功能設(shè)計(jì)的比較簡(jiǎn)單、只有商品信息的增刪改查。實(shí)現(xiàn)對(duì)商品信息全面、 動(dòng)態(tài)、及時(shí)的管理。本文系統(tǒng)的分析了軟件開發(fā)的背景以過(guò)程;首先介紹了軟件的開發(fā)環(huán)境, 其次介紹了本軟件的詳細(xì)設(shè)計(jì)過(guò)程: 數(shù)據(jù)庫(kù)的設(shè)計(jì)、各個(gè)模塊的設(shè)計(jì)和實(shí)現(xiàn),以及具體界面的設(shè)計(jì)和功能。超市庫(kù)存管理系統(tǒng)是基于 Java eclipse 作為開發(fā)工具 , Mysql 作為后臺(tái)數(shù)據(jù)庫(kù)支持。超市庫(kù)存管理系統(tǒng)開發(fā)主要是界面程序的開發(fā)、數(shù)據(jù)庫(kù)的建立、數(shù)據(jù)庫(kù)的維護(hù)。應(yīng)用程序功能完善,界面人機(jī)交互要好,而且操作簡(jiǎn)單。同時(shí) JAVASwing語(yǔ)言簡(jiǎn)單,在較短的時(shí)間內(nèi)能夠開發(fā)出使用性強(qiáng)、 功能完善, 易于操作的程序, 也能實(shí)現(xiàn)與數(shù)據(jù)庫(kù)的連接。
主要模塊:
商品列表數(shù)據(jù)展示、商品信息添加、商品信息修改、商品信息刪除、按照商品名稱查詢商品信息
1、功能介紹
功能截圖:
查詢商品列表信息:
添加商品信息:
修改商品信息:
刪除商品信息:
刪除之后需要刷新一下列表數(shù)據(jù)
編號(hào)查詢商品信息:
2、關(guān)鍵代碼
2.1 主頁(yè)功能
public class GoodsManage extends JFrame { private JTextField textField; Select select = new Select(); Updata updata = new Updata(); Object[] header= {"商品編號(hào)","商品名稱","數(shù)量","單價(jià)"}; 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, "請(qǐng)選擇要修改的數(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, "請(qǐng)選中要?jiǎng)h除的數(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("商品編號(hào):"); 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("按編號(hào)查詢"); 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); //加入動(dòng)作 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("商品編號(hào):"); 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("單價(jià):"); 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, "請(qǐng)完整輸入要添加的數(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ù)庫(kù)設(shè)計(jì)
商品表
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è)計(jì)與實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Mysql+JavaSwing
的超市商品管理系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
關(guān)于com.mysql.jdbc.Driver與com.mysql.cj.jdbc.Driver的區(qū)別
這篇文章主要介紹了關(guān)于com.mysql.jdbc.Driver與com.mysql.cj.jdbc.Driver的區(qū)別及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-08-08在MySQL數(shù)據(jù)庫(kù)中使用C執(zhí)行SQL語(yǔ)句的方法
與PostgreSQL相似,可使用許多不同的語(yǔ)言來(lái)訪問(wèn)MySQL,包括C、C++、Java和Perl。從Professional Linux Programming中第5章有關(guān)MySQL的下列章節(jié)中,Neil Matthew和Richard Stones使用詳盡的MySQL C接口向我們介紹了如何在MySQL數(shù)據(jù)庫(kù)中執(zhí)行SQL語(yǔ)句。2012-10-10mysql數(shù)據(jù)庫(kù)中字符集亂碼問(wèn)題原因及解決
這篇文章主要介紹了mysql數(shù)據(jù)庫(kù)中字符集亂碼問(wèn)題原因及解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08MySQL中的insert set 和 insert values用法
這篇文章主要介紹了MySQL中的insert set 和 insert values用法說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08Mysql關(guān)于進(jìn)程中的死鎖和解除鎖問(wèn)題
Mysql 經(jīng)常會(huì)遇到語(yǔ)句或者存儲(chǔ)過(guò)程長(zhǎng)時(shí)間沒(méi)有反應(yīng),大概率就是掛掉了,或者死鎖了,這篇文章主要介紹了Mysql關(guān)于進(jìn)程中的死鎖和解除鎖問(wèn)題,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-07-07MySQL兩個(gè)查詢?nèi)绾魏喜⒊梢粋€(gè)結(jié)果詳解
利用union關(guān)鍵字,可以給出多條select語(yǔ)句,并將它們的結(jié)果組合成單個(gè)結(jié)果集,下面這篇文章主要給大家介紹了關(guān)于MySQL兩個(gè)查詢?nèi)绾魏喜⒊梢粋€(gè)結(jié)果的相關(guān)資料,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08MySQL中主鍵為0與主鍵自排約束的關(guān)系詳解(細(xì)節(jié))
這篇文章主要給大家介紹了關(guān)于MySQL中主鍵為0與主鍵自排約束的關(guān)系的相關(guān)資料,主要介紹的是其中的一些非常細(xì)的細(xì)節(jié),對(duì)大家學(xué)習(xí)或者使用mysql具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-05-05Mysql誤刪數(shù)據(jù)解決方案及kill語(yǔ)句原理
這篇文章主要介紹了Mysql誤刪數(shù)據(jù)解決方案及kill語(yǔ)句原理,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09