MainFrm.java
package com.sjsq.view; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import java.awt.Toolkit; import javax.swing.JDesktopPane; import javax.swing.JMenuBar; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.ImageIcon; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; /** * 主页面视图层 * * @author shuijianshiqing * */ public class MainFrm extends JFrame { private JPanel contentPane; private JDesktopPane table; /** * 创建窗体 */ public MainFrm() { setTitle("仓库系统主界面"); setIconImage(Toolkit.getDefaultToolkit().getImage(MainFrm.class.getResource("/images/goods_logo.png"))); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 200, 900, 800); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu menu = new JMenu("仓库系统管理"); menu.setIcon(new ImageIcon(MainFrm.class.getResource("/images/manager.png"))); menuBar.add(menu); JMenu menu_2 = new JMenu("仓库系统管理"); menu_2.setIcon(new ImageIcon(MainFrm.class.getResource("/images/goodmanager.png"))); menu.add(menu_2); JMenuItem menuItem_2 = new JMenuItem("货物类型添加"); menuItem_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { GoodsTypeAddInterFrm goodsTypeAddInterFrm = new GoodsTypeAddInterFrm(); goodsTypeAddInterFrm.setVisible(true); table.add(goodsTypeAddInterFrm); } }); menuItem_2.setIcon(new ImageIcon(MainFrm.class.getResource("/images/add.png"))); menu_2.add(menuItem_2); JMenuItem menuItem_3 = new JMenuItem("货物类型修改"); menuItem_3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { GoodsTypeManagerInterFrm goodsTypeManagerInterFrm = new GoodsTypeManagerInterFrm(); goodsTypeManagerInterFrm.setVisible(true); table.add(goodsTypeManagerInterFrm); } }); menuItem_3.setIcon(new ImageIcon(MainFrm.class.getResource("/images/modify.png"))); menu_2.add(menuItem_3); JMenu menu_3 = new JMenu("货物物品管理"); menu_3.setIcon(new ImageIcon(MainFrm.class.getResource("/images/goods.png"))); menu.add(menu_3); JMenuItem menuItem_4 = new JMenuItem("货物物品添加"); menuItem_4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { GoodsAddInterFrm goodsAddInterFrm = new GoodsAddInterFrm(); goodsAddInterFrm.setVisible(true); table.add(goodsAddInterFrm); } }); menuItem_4.setIcon(new ImageIcon(MainFrm.class.getResource("/images/add.png"))); menu_3.add(menuItem_4); JMenuItem menuItem_5 = new JMenuItem("货物物品修改"); menuItem_5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { GoodsManagerInterFrm goodsManagerInterFrm = new GoodsManagerInterFrm(); goodsManagerInterFrm.setVisible(true); table.add(goodsManagerInterFrm); } }); menuItem_5.setIcon(new ImageIcon(MainFrm.class.getResource("/images/modify.png"))); menu_3.add(menuItem_5); JMenuItem menuItem_1 = new JMenuItem("安全退出"); menuItem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { exitSystemActionPerformed(e); } }); menuItem_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/exit.png"))); menu.add(menuItem_1); JMenu menu_1 = new JMenu("联系我们"); menu_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/contact.png"))); menuBar.add(menu_1); JMenuItem menuItem = new JMenuItem("联系方式"); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { MyContactInterFrm myContactInterFrm = new MyContactInterFrm(); myContactInterFrm.setVisible(true); table.add(myContactInterFrm); } }); menuItem.setIcon(new ImageIcon(MainFrm.class.getResource("/images/phnoe.png"))); menu_1.add(menuItem); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); table = new JDesktopPane(); contentPane.add(table, BorderLayout.CENTER); // 居中显示 this.setLocationRelativeTo(null); // 最大化处理 // this.setExtendedState(JFrame.MAXIMIZED_BOTH); } /** * 安全退出系统 * * @param e */ private void exitSystemActionPerformed(ActionEvent e) { int n = JOptionPane.showConfirmDialog(null, "你确定要离开系统么"); if (n == 0) { dispose(); return; } } /** * 运行程序 */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { MainFrm frame = new MainFrm(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } }
GoodsAddInterFrm.java
package com.sjsq.view; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import javax.swing.ButtonGroup; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JRadioButton; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.LayoutStyle.ComponentPlacement; import com.sjsq.dao.GoodsDao; import com.sjsq.dao.GoodsTypeDao; import com.sjsq.model.Goods; import com.sjsq.model.GoodsType; import com.sjsq.util.DbUtil; import com.sjsq.util.StringUtil; import javax.swing.ImageIcon; /** * 货物添加视图层 * * @author shuijianshiqing * */ public class GoodsAddInterFrm extends JInternalFrame { private JTextField goodsNameTxt; private JTextField goodsSupplierTxt; private JTextField priceTxt; private JTextArea goodsDescTxt; private JComboBox goodsTypeNameJcb; private JRadioButton manJrb; private JRadioButton femaleJrb; private final ButtonGroup buttonGroup = new ButtonGroup(); private static DbUtil dbUtil = new DbUtil(); private static GoodsDao goodsDao = new GoodsDao(); /** * 创建窗体 */ public GoodsAddInterFrm() { setClosable(true); setIconifiable(true); setTitle("货物添加"); setBounds(100, 100, 596, 399); JLabel lblNewLabel = new JLabel("货物名称:"); goodsNameTxt = new JTextField(); goodsNameTxt.setColumns(10); JLabel lblNewLabel_1 = new JLabel("货物供应商:"); goodsSupplierTxt = new JTextField(); goodsSupplierTxt.setColumns(10); JLabel label = new JLabel("供应商性别:"); manJrb = new JRadioButton("男"); buttonGroup.add(manJrb); manJrb.setSelected(true); femaleJrb = new JRadioButton("女"); buttonGroup.add(femaleJrb); JLabel lblNewLabel_2 = new JLabel("货物价格:"); priceTxt = new JTextField(); priceTxt.setColumns(10); JLabel label_1 = new JLabel("货物类别:"); goodsTypeNameJcb = new JComboBox(); JLabel label_2 = new JLabel("货物描述:"); goodsDescTxt = new JTextArea(); JButton button = new JButton("添加"); button.setIcon(new ImageIcon(GoodsAddInterFrm.class.getResource("/images/add.png"))); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { addGoodsActionPerformed(arg0); } }); JButton button_1 = new JButton("重置"); button_1.setIcon(new ImageIcon(GoodsAddInterFrm.class.getResource("/images/reset.png"))); button_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { resetValueActionPerformed(e); } }); GroupLayout groupLayout = new GroupLayout(getContentPane()); groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout .createSequentialGroup() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup().addGap(45) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout .createSequentialGroup().addComponent(label_2).addGap( 3) .addComponent(goodsDescTxt, GroupLayout.PREFERRED_SIZE, 346, GroupLayout.PREFERRED_SIZE)) .addGroup(groupLayout.createSequentialGroup().addGroup(groupLayout .createParallelGroup(Alignment.LEADING, false) .addGroup(groupLayout.createSequentialGroup().addComponent(label_1) .addPreferredGap(ComponentPlacement.RELATED).addComponent( goodsTypeNameJcb, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(groupLayout.createSequentialGroup().addComponent(lblNewLabel) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(goodsNameTxt, GroupLayout.PREFERRED_SIZE, 99, GroupLayout.PREFERRED_SIZE)) .addGroup(groupLayout.createSequentialGroup().addComponent(label) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(manJrb) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(femaleJrb))) .addGap(65) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false) .addGroup(groupLayout .createSequentialGroup().addComponent(lblNewLabel_1) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(goodsSupplierTxt, GroupLayout.PREFERRED_SIZE, 102, GroupLayout.PREFERRED_SIZE)) .addGroup(groupLayout.createSequentialGroup() .addComponent(lblNewLabel_2).addGap(18) .addComponent(priceTxt)))))) .addGroup(groupLayout.createSequentialGroup().addGap(149).addComponent(button).addGap(119) .addComponent(button_1))) .addContainerGap(126, Short.MAX_VALUE))); groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup().addGap(38) .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel) .addComponent(goodsNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(lblNewLabel_1).addComponent(goodsSupplierTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGap(28) .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(label) .addComponent(manJrb).addComponent(femaleJrb).addComponent(lblNewLabel_2) .addComponent(priceTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGap(28) .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(label_1) .addComponent(goodsTypeNameJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup().addGap(35).addComponent(label_2)) .addGroup(groupLayout.createSequentialGroup().addGap(36).addComponent(goodsDescTxt, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE))) .addPreferredGap(ComponentPlacement.RELATED, 25, Short.MAX_VALUE).addGroup(groupLayout .createParallelGroup(Alignment.BASELINE).addComponent(button_1).addComponent(button)) .addGap(22))); getContentPane().setLayout(groupLayout); // 填充下拉列表 this.fillGoodsType(); } /** * 货物添加事件 * * @param arg0 */ private void addGoodsActionPerformed(ActionEvent arg0) { String goodsName = this.goodsNameTxt.getText(); String goodsSupplier = this.goodsSupplierTxt.getText(); String price = this.priceTxt.getText(); String goodsDesc = this.goodsDescTxt.getText(); if (StringUtil.isEmpty(goodsName)) { JOptionPane.showMessageDialog(null, "货物名称不能为空!"); return; } if (StringUtil.isEmpty(goodsSupplier)) { JOptionPane.showMessageDialog(null, "货物供货商不能为空!"); return; } if (StringUtil.isEmpty(goodsDesc)) { JOptionPane.showMessageDialog(null, "货物描述不能为空!"); return; } if (StringUtil.isEmpty(price)) { JOptionPane.showMessageDialog(null, "货物价格不能为空!"); return; } String sex = ""; if (manJrb.isSelected()) { sex = "男"; } else if (femaleJrb.isSelected()) { sex = "女"; } GoodsType goodsTypeName = (GoodsType) this.goodsTypeNameJcb.getSelectedItem(); int goodsTypeId = goodsTypeName.getId(); String goodsTypeNames = goodsTypeName.getGoodsTypeName(); Goods goods = new Goods(goodsName, goodsSupplier, sex, Double.parseDouble(price), goodsDesc, goodsTypeId,goodsTypeNames); Connection conn = null; try { conn = DbUtil.getCon(); int result = goodsDao.addGoods(conn, goods); if (result == 1) { JOptionPane.showMessageDialog(null, "货物添加成功!"); this.resetValue(); } else { JOptionPane.showMessageDialog(null, "货物添加失败!"); } } catch (Exception e) { e.printStackTrace(); } finally { try { dbUtil.close(conn); } catch (SQLException e) { e.printStackTrace(); } } } /** * 货物表单重置事件 * * @param e */ private void resetValueActionPerformed(ActionEvent e) { this.resetValue(); } /** * 表单重置事件 */ private void resetValue() { this.goodsNameTxt.setText(""); this.goodsSupplierTxt.setText(""); this.priceTxt.setText(""); this.goodsDescTxt.setText(""); this.manJrb.setSelected(true); if (goodsTypeNameJcb.getItemCount() > 0) { goodsTypeNameJcb.setSelectedIndex(0); } } /** * 填充下拉列表货物类型 */ private void fillGoodsType() { Connection conn = null; GoodsType goodsType = null; ResultSet rs = null; try { conn = DbUtil.getCon(); rs = GoodsTypeDao.listGoodsType(conn, new GoodsType()); while (rs.next()) { goodsType = new GoodsType(); goodsType.setId(rs.getInt("id")); goodsType.setGoodsTypeName(rs.getString("goodsTypeName")); this.goodsTypeNameJcb.addItem(goodsType); } } catch (Exception e) { e.printStackTrace(); } finally { try { DbUtil.close(conn, rs); } catch (SQLException e) { e.printStackTrace(); } } } /** * 运行程序 */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { GoodsAddInterFrm frame = new GoodsAddInterFrm(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } }
GoodsManagerInterFrm.java
package com.sjsq.view; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Vector; import javax.swing.ButtonGroup; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.border.TitledBorder; import javax.swing.table.DefaultTableModel; import com.sjsq.dao.GoodsDao; import com.sjsq.dao.GoodsTypeDao; import com.sjsq.model.Goods; import com.sjsq.model.GoodsType; import com.sjsq.util.DbUtil; import com.sjsq.util.StringUtil; /** * 货物管理视图层 * * @author shuijianshiqing * */ public class GoodsManagerInterFrm extends JInternalFrame { private JTable goodsTable; private JTextField s_goodsNameTxt; private JTextField s_goodsSupplierTxt; private JTextField goodsIdTxt; private JTextField goodsNameTxt; private JTextField priceTxt; private JTextField goodsSupplierTxt; private JTextArea goodsDescTxt; private JComboBox goodsTypeNameJcb; private JRadioButton manJrb; private JRadioButton femaleJrb; private JComboBox s_goodsTypeNameJcbTxt; private final ButtonGroup buttonGroup = new ButtonGroup(); private static DbUtil dbUtil = new DbUtil(); private static GoodsDao goodsDao = new GoodsDao(); private static GoodsTypeDao goodsTypeDao = new GoodsTypeDao(); /** * 创建窗体 */ public GoodsManagerInterFrm() { setTitle("货物物品管理"); setIconifiable(true); setClosable(true); setBounds(100, 100, 732, 532); JScrollPane scrollPane = new JScrollPane(); JPanel panel = new JPanel(); panel.setBorder( new TitledBorder(null, "货物物品添加", TitledBorder.LEADING, TitledBorder.TOP, null, null)); // 搜索部分 JLabel label = new JLabel("货物名称:"); s_goodsNameTxt = new JTextField(); s_goodsNameTxt.setColumns(10); JLabel label_1 = new JLabel("供货商:"); s_goodsSupplierTxt = new JTextField(); s_goodsSupplierTxt.setColumns(10); JLabel label_2 = new JLabel("货物类别:"); s_goodsTypeNameJcbTxt = new JComboBox(); JButton button = new JButton("搜索:"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { searchGoodsActionPerformed(arg0); } }); button.setIcon(new ImageIcon(GoodsManagerInterFrm.class.getResource("/images/Search.png"))); GroupLayout gl_panel = new GroupLayout(panel); gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(gl_panel .createSequentialGroup().addContainerGap().addComponent(label) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(s_goodsNameTxt, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE).addGap(30) .addComponent(label_1).addPreferredGap(ComponentPlacement.RELATED) .addComponent(s_goodsSupplierTxt, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE).addGap(18) .addComponent(label_2).addPreferredGap(ComponentPlacement.RELATED) .addComponent(s_goodsTypeNameJcbTxt, GroupLayout.PREFERRED_SIZE, 119, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED, 22, Short.MAX_VALUE).addComponent(button) .addContainerGap())); gl_panel.setVerticalGroup( gl_panel.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel.createSequentialGroup().addContainerGap() .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(label) .addComponent(s_goodsNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(label_1) .addComponent(s_goodsSupplierTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(label_2) .addComponent(s_goodsTypeNameJcbTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(button)) .addContainerGap(17, Short.MAX_VALUE))); panel.setLayout(gl_panel); // 修改部分 JPanel panel_1 = new JPanel(); panel_1.setBorder( new TitledBorder(null, "货物物品修改", TitledBorder.LEADING, TitledBorder.TOP, null, null)); GroupLayout groupLayout = new GroupLayout(getContentPane()); groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.TRAILING) .addGroup(groupLayout.createSequentialGroup().addGap(31) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addComponent(panel_1, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(Alignment.TRAILING, groupLayout.createParallelGroup(Alignment.LEADING, false) .addComponent(panel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 631, Short.MAX_VALUE))) .addGap(40))); groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup().addGap(23) .addComponent(panel, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE).addGap(18) .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 119, GroupLayout.PREFERRED_SIZE) .addGap(18).addComponent(panel_1, GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE) .addContainerGap())); JLabel lblNewLabel = new JLabel("货物名称:"); goodsIdTxt = new JTextField(); goodsIdTxt.setEnabled(false); goodsIdTxt.setColumns(10); JLabel label_3 = new JLabel("货物名称:"); goodsNameTxt = new JTextField(); goodsNameTxt.setColumns(10); JLabel label_4 = new JLabel("供货商性别:"); manJrb = new JRadioButton("男"); buttonGroup.add(manJrb); manJrb.setSelected(true); femaleJrb = new JRadioButton("女"); buttonGroup.add(femaleJrb); JLabel lblNewLabel_1 = new JLabel("\u8D27\u7269\u4EF7\u683C\uFF1A"); priceTxt = new JTextField(); priceTxt.setColumns(10); JLabel label_5 = new JLabel("货物价格:"); goodsSupplierTxt = new JTextField(); goodsSupplierTxt.setColumns(10); JLabel label_6 = new JLabel("供货商:"); goodsTypeNameJcb = new JComboBox(); JLabel label_7 = new JLabel("货物类别:"); goodsDescTxt = new JTextArea(); JButton button_1 = new JButton("修改"); button_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { modifyGoodsActionPerformed(arg0); } }); button_1.setIcon(new ImageIcon(GoodsManagerInterFrm.class.getResource("/images/modify.png"))); JButton button_2 = new JButton("重置"); button_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { resetValueActionPerformed(arg0); } }); button_2.setIcon(new ImageIcon(GoodsManagerInterFrm.class.getResource("/images/reset.png"))); JButton button_3 = new JButton("删除"); button_3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { deleteGoodsActionPerformed(arg0); } }); button_3.setIcon(new ImageIcon(GoodsManagerInterFrm.class.getResource("/images/delete.png"))); GroupLayout gl_panel_1 = new GroupLayout(panel_1); gl_panel_1.setHorizontalGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_1 .createSequentialGroup().addContainerGap() .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_1.createSequentialGroup() .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_1 .createSequentialGroup().addComponent(lblNewLabel) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(goodsIdTxt, GroupLayout.PREFERRED_SIZE, 53, GroupLayout.PREFERRED_SIZE) .addGap(26).addComponent(label_3).addPreferredGap(ComponentPlacement.RELATED) .addComponent(goodsNameTxt, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_panel_1.createSequentialGroup().addComponent(lblNewLabel_1) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(priceTxt, GroupLayout.PREFERRED_SIZE, 84, GroupLayout.PREFERRED_SIZE) .addGap(26).addComponent(label_5).addPreferredGap(ComponentPlacement.RELATED) .addComponent(goodsSupplierTxt, GroupLayout.PREFERRED_SIZE, 112, GroupLayout.PREFERRED_SIZE))) .addGap(50) .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_1.createSequentialGroup().addComponent(label_4) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(manJrb).addGap(18) .addComponent(femaleJrb)) .addGroup(gl_panel_1.createSequentialGroup().addComponent(label_6).addGap(18) .addComponent(goodsTypeNameJcb, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE)))) .addComponent(label_7).addComponent(goodsDescTxt, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 518, GroupLayout.PREFERRED_SIZE)) .addContainerGap(30, Short.MAX_VALUE)) .addGroup(gl_panel_1.createSequentialGroup().addGap(93).addComponent(button_1) .addPreferredGap(ComponentPlacement.RELATED, 128, Short.MAX_VALUE).addComponent(button_2) .addGap(112).addComponent(button_3).addGap(69))); gl_panel_1.setVerticalGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_1 .createSequentialGroup().addGap( 21) .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel) .addComponent(goodsIdTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(label_3) .addComponent(goodsNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(femaleJrb).addComponent(manJrb).addComponent(label_4)) .addGap(18) .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_1) .addComponent(priceTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(label_5) .addComponent(goodsSupplierTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(label_6).addComponent(goodsTypeNameJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGap(18) .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addComponent(label_7) .addComponent(goodsDescTxt, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED, 29, Short.MAX_VALUE) .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(button_1) .addComponent(button_3).addComponent(button_2)) .addContainerGap())); panel_1.setLayout(gl_panel_1); goodsTable = new JTable(); goodsTable.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent arg0) { MouseClickGoodsTableActionPerformed(arg0); } }); goodsTable.setModel(new DefaultTableModel(new Object[][] {}, new String[] { "货物编号", "货物名称","供货商", "性别", "货物价格", "货物描述", "货物类别" }) { boolean[] columnEditables = new boolean[] { false, false, false, false, false, false, false }; public boolean isCellEditable(int row, int column) { return columnEditables[column]; } }); scrollPane.setViewportView(goodsTable); getContentPane().setLayout(groupLayout); // 填充表单 this.fillGoodsTable(new Goods()); this.fillGoodsTypeNameItem("search"); this.fillGoodsTypeNameItem("modify"); } /** * 货物删除事件 * * @param arg0 */ private void deleteGoodsActionPerformed(ActionEvent arg0) { String id = this.goodsIdTxt.getText(); if (StringUtil.isEmpty(id)) { JOptionPane.showMessageDialog(null, "请选择要删除的货物"); return; } int n = JOptionPane.showConfirmDialog(null, "确定要删除此货物?"); Goods goods = new Goods(Integer.parseInt(id)); if (n == 0) { Connection conn = null; try { conn = dbUtil.getCon(); int result = goodsDao.deleteGoods(conn, goods); if (result == 1) { JOptionPane.showMessageDialog(null, "货物删除成功!"); this.resetValue(); this.fillGoodsTable(new Goods()); } else { JOptionPane.showMessageDialog(null, "货物删除失败!"); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "货物删除失败!"); } finally { try { dbUtil.close(conn); } catch (SQLException e) { e.printStackTrace(); } } } } /** * 货物修改事件 * * @param a */ private void modifyGoodsActionPerformed(Object a) { String id = this.goodsIdTxt.getText(); String goodsName = this.goodsNameTxt.getText(); String price = this.priceTxt.getText(); String goodsSupplier = this.goodsSupplierTxt.getText(); String goodsDesc = this.goodsDescTxt.getText(); if (StringUtil.isEmpty(id)) { JOptionPane.showMessageDialog(null, "请选择要修改的货物"); return; } if (StringUtil.isEmpty(goodsName)) { JOptionPane.showMessageDialog(null, "货物名称不能为空!"); return; } if (StringUtil.isEmpty(price)) { JOptionPane.showMessageDialog(null, "货物价格不能为空!"); return; } if (StringUtil.isEmpty(goodsSupplier)) { JOptionPane.showMessageDialog(null, "供货商名称不能为空!"); return; } if (StringUtil.isEmpty(goodsDesc)) { JOptionPane.showMessageDialog(null, "货物描述不能为空!"); return; } String sex = ""; if (manJrb.isSelected()) { sex = "男"; } else if (femaleJrb.isSelected()) { sex = "女"; } GoodsType goodsType = (GoodsType) this.goodsTypeNameJcb.getSelectedItem(); int goodsTypeId = goodsType.getId(); Goods goods = new Goods(Integer.parseInt(id), goodsName, goodsSupplier, sex, Double.parseDouble(price), goodsDesc, goodsTypeId); Connection conn = null; try { conn = DbUtil.getCon(); int result = GoodsDao.updateGoods(conn, goods); if (result == 1) { JOptionPane.showMessageDialog(null, "货物修改成功!"); this.fillGoodsTable(new Goods()); } else { JOptionPane.showMessageDialog(null, "货物修改失败!"); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "货物修改失败!"); } finally { try { dbUtil.close(conn); } catch (SQLException e) { e.printStackTrace(); } } } /** * 货物搜索事件 * * @param arg0 */ private void searchGoodsActionPerformed(ActionEvent arg0) { String goodsName = this.s_goodsNameTxt.getText(); String goodsSupplier = this.s_goodsSupplierTxt.getText(); GoodsType goodsType = (GoodsType) this.s_goodsTypeNameJcbTxt.getSelectedItem(); int goodsTypeId = goodsType.getId(); Goods goods = new Goods(goodsName, goodsSupplier, goodsTypeId); this.fillGoodsTable(goods); } /** * 填充下拉列表菜单 * * @param type */ private void fillGoodsTypeNameItem(String type) { Connection conn = null; GoodsType goodsType = null; ResultSet rs = null; try { conn = dbUtil.getCon(); rs = goodsTypeDao.listGoodsType(conn, new GoodsType()); if ("search".equals(type)) { goodsType = new GoodsType(); goodsType.setGoodsTypeName("请选择..."); goodsType.setId(-1); this.s_goodsTypeNameJcbTxt.addItem(goodsType); } while (rs.next()) { goodsType = new GoodsType(); goodsType.setId(rs.getInt("id")); goodsType.setGoodsTypeName(rs.getString("goodsTypeName")); if ("search".equals(type)) { this.s_goodsTypeNameJcbTxt.addItem(goodsType); } else if ("modify".equals(type)) { this.goodsTypeNameJcb.addItem(goodsType); } } } catch (Exception e) { e.printStackTrace(); } finally { try { dbUtil.close(conn, rs); } catch (SQLException e) { e.printStackTrace(); } } } /** * 填充表单事件 * * @param goods */ private void fillGoodsTable(Goods goods) { DefaultTableModel dtm = (DefaultTableModel) goodsTable.getModel(); dtm.setRowCount(0); Connection conn = null; ResultSet rs = null; try { conn = DbUtil.getCon(); rs = goodsDao.listGoods(conn, goods); while (rs.next()) { Vector v = new Vector(); v.add(rs.getString("id")); v.add(rs.getString("goodsName")); v.add(rs.getString("goodsSupplier")); v.add(rs.getString("sex")); v.add(rs.getString("price")); v.add(rs.getString("goodsDesc")); v.add(rs.getString("goodsTypeName")); dtm.addRow(v); } } catch (Exception e) { e.printStackTrace(); } finally { try { dbUtil.close(conn, rs); } catch (SQLException e) { e.printStackTrace(); } } } /** * 鼠标点击事件 * * @param arg0 */ private void MouseClickGoodsTableActionPerformed(MouseEvent arg0) { int row = this.goodsTable.getSelectedRow(); this.goodsIdTxt.setText(goodsTable.getValueAt(row, 0) + ""); this.goodsNameTxt.setText(goodsTable.getValueAt(row, 1) + ""); this.goodsSupplierTxt.setText(goodsTable.getValueAt(row, 2) + ""); String sex = (String) goodsTable.getValueAt(row, 3); if ("男".equals(sex)) { this.manJrb.setSelected(true); } else if ("女".equals(sex)) { this.femaleJrb.setSelected(true); } this.priceTxt.setText(goodsTable.getValueAt(row, 4) + ""); this.goodsDescTxt.setText(goodsTable.getValueAt(row, 5) + ""); String goodsTypeName = (String) this.goodsTable.getValueAt(row, 6); int n = this.goodsTypeNameJcb.getItemCount(); for (int i = 0; i < n; i++) { GoodsType item = (GoodsType) this.goodsTypeNameJcb.getItemAt(i); if (item.getGoodsTypeName().equals(goodsTypeName)) { this.goodsTypeNameJcb.setSelectedIndex(i); } } } /** * 重置事件 * * @param arg0 */ private void resetValueActionPerformed(ActionEvent arg0) { this.resetValue(); } /** * 重置表单 */ private void resetValue() { this.goodsIdTxt.setText(""); this.goodsNameTxt.setText(""); this.goodsSupplierTxt.setText(""); this.priceTxt.setText(""); this.goodsDescTxt.setText(""); this.manJrb.setSelected(true); // 下拉菜单的重置 if (this.goodsTypeNameJcb.getItemCount() > 0) { this.goodsTypeNameJcb.setSelectedIndex(0); } } /** * 运行程序 */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { GoodsManagerInterFrm frame = new GoodsManagerInterFrm(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } }
四、其他
JavaWeb系统系列实现
Java+JSP实现学生图书管理系统
Java+JSP实现学生信息管理系统
Java+JSP实现用户信息管理系统
Java+Servlet+JSP实现航空订票系统
Java+Servlet+JSP实现房屋租赁管理系统
Java+Servlet+JSP实现学生选课管理系统
Java+Servlet+JSP实现学生成绩管理系统
Java+Servlet+JSP实现宠物诊所管理系统
Java+SSM+Easyui实现网上考试系统
Java+Springboot+H-ui实现营销管理系统
Java+Springboot+Mybatis+Bootstrap实现网上商城系统
JavaSwing系统系列实现
Java+Swing实现斗地主游戏
Java+Swing实现图书管理系统
Java+Swing实现医院管理系统
Java+Swing实现仓库管理系统
Java+Swing实现考试管理系统
Java+Swing实现通讯录管理系统
Java+Swing实现停车场管理系统
Java+Swing实现学生信息管理系统
Java+Swing实现学生宿舍管理系统
Java+Swing实现学生选课管理系统
Java+Swing实现学生成绩管理系统
Java+Swing实现学校教材管理系统
Java+Swing实现学校教务管理系统
Java+Swing实现企业人事管理系统
Java+Swing实现电子相册管理系统
Java+Swing实现自助取款机(ATM)系统
Java+Swing实现超市管理系统-TXT存储信息
Java+Swing实现宠物商店管理系统-TXT存储信息
2.获取源码
点击以下链接获取源码
Java+Swing+Mysql实现仓库管理系统源码
3.运行项目
请走点击以下链接,部署你的项目。
Eclipse如何导入JavaSwing项目超详细教程