基于Mysql+JavaSwing的超市商品管理系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)

:
隨著小超市規(guī)模的發(fā)展不斷擴(kuò)大, 商品數(shù)量急劇增加, 有關(guān)商品的各種信息量也成倍增長。 超市時(shí)時(shí)刻刻都需要對(duì)商品各種信息進(jìn)行統(tǒng)計(jì)分析。 而大型的超市管理系統(tǒng)功能過于強(qiáng)大而造成操作繁瑣降低了小超市的工作效率。 超市管理系統(tǒng)是市場上最流行的超市上常用的系統(tǒng)之一, 由于剛學(xué)Java知識(shí)、所有功能設(shè)計(jì)的比較簡單、只有商品信息的增刪改查。實(shí)現(xiàn)對(duì)商品信息全面、 動(dòng)態(tài)、及時(shí)的管理。本文系統(tǒng)的分析了軟件開發(fā)的背景以過程;首先介紹了軟件的開發(fā)環(huán)境, 其次介紹了本軟件的詳細(xì)設(shè)計(jì)過程: 數(shù)據(jù)庫的設(shè)計(jì)、各個(gè)模塊的設(shè)計(jì)和實(shí)現(xiàn),以及具體界面的設(shè)計(jì)和功能。超市庫存管理系統(tǒng)是基于 Java eclipse 作為開發(fā)工具 , Mysql 作為后臺(tái)數(shù)據(jù)庫支持。超市庫存管理系統(tǒng)開發(fā)主要是界面程序的開發(fā)、數(shù)據(jù)庫的建立、數(shù)據(jù)庫的維護(hù)。應(yīng)用程序功能完善,界面人機(jī)交互要好,而且操作簡單。同時(shí) JAVASwing語言簡單,在較短的時(shí)間內(nèi)能夠開發(fā)出使用性強(qiáng)、 功能完善, 易于操作的程序, 也能實(shí)現(xiàn)與數(shù)據(jù)庫的連接。
主要模塊:
商品列表數(shù)據(jù)展示、商品信息添加、商品信息修改、商品信息刪除、按照商品名稱查詢商品信息
1、功能介紹
功能截圖:
查詢商品列表信息:

添加商品信息:

修改商品信息:

刪除商品信息:
刪除之后需要刷新一下列表數(shù)據(jù)

編號(hào)查詢商品信息:

2、關(guān)鍵代碼
2.1 主頁功能
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ù)庫設(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)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信