1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| }); 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) {
|