基于java+mysql的swing+mysql购物商城(java+swing+mysql+gui)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于java+mysql的Swing+MySQL购物商城(java+swing+mysql+gui)
管理员登录:ManagerLogOnFrm
admin 123456
用户购物:FuntionMainFrm
user1 123456
user2 123456
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
productTable = new javax.swing.JTable();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
s_productNameTxt = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
s_productTimeTxt = new javax.swing.JTextField();
s_jcbProductType = new javax.swing.JComboBox();
jLabel3 = new javax.swing.JLabel();
jb_search = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
idTxt = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
productNameTxt = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
priceTxt = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
productTimeTxt = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
jcb_productType = new javax.swing.JComboBox();
jLabel9 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
productDescTxt = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
productTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(idTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(productNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(priceTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7)
.addComponent(productTimeTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8)
.addComponent(jcb_productType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(34, 34, 34)))
.addGap(25, 25, 25))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap())))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 691, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
private void productTableMousePressed(java.awt.event.MouseEvent evt) {
//获取选中的行
int row = this.productTable.getSelectedRow();
this.idTxt.setText((Integer) productTable.getValueAt(row, 0) + "");
this.productNameTxt.setText((String) productTable.getValueAt(row, 1));
this.productTimeTxt.setText((String) productTable.getValueAt(row, 2));
this.priceTxt.setText((Float) productTable.getValueAt(row, 3) + "");
this.productDescTxt.setText((String) productTable.getValueAt(row, 4));
String productTypeName = (String) productTable.getValueAt(row, 5);
int n = this.jcb_productType.getItemCount();
for (int i = 0; i < n; i++) {
ProductType item = (ProductType) this.jcb_productType.getItemAt(i);
if (item.getProductTypeName().equals(productTypeName)) {
this.jcb_productType.setSelectedIndex(i);
}
}
this.jcb_productType.setEnabled(false);
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JTable ProductChosenTable;
private javax.swing.JTextField idTxt;
private javax.swing.JDialog jDialog1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JButton jb_cost;
private javax.swing.JButton jb_delete;
private javax.swing.JButton jb_putProductIntoCar;
"./images/userName.png")); // NOI18N
jLabel2.setText("\u7528\u6237\u540d");
jLabel3.setIcon(new javax.swing.ImageIcon(
"./images\\password.png")); // NOI18N
jLabel3.setText("\u5bc6\u7801");
userNameTxt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
userNameTxtActionPerformed(evt);
}
});
jb_logon.setIcon(new javax.swing.ImageIcon(
"./images\\login.png")); // NOI18N
jb_logon.setText("\u767b\u9646");
jb_logon.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_logonActionPerformed(evt);
}
});
jb_reset.setIcon(new javax.swing.ImageIcon(
"./images\\reset.png")); // NOI18N
jb_reset.setText("\u91cd\u7f6e");
jb_reset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_resetActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup().addContainerGap(
148, Short.MAX_VALUE).addComponent(
jLabel1).addGap(132, 132, 132))
private int productTypeId=-1;
private String ProductTypeName;
public Product() {
super();
// TODO Auto-generated constructor stub
}
public Product(int id, String productName, String productTime, float price,
String productDesc, int productTypeId) {
super();
this.id = id;
this.productName = productName;
this.productTime = productTime;
this.price = price;
this.productDesc = productDesc;
this.productTypeId = productTypeId;
}
public Product(String productName, String productTime, float price,
String productDesc, int productTypeId) {
super();
this.productName = productName;
this.productTime = productTime;
this.price = price;
this.productDesc = productDesc;
this.productTypeId = productTypeId;
}
public Product(String productName, String productTime, int productTypeId) {
super();
this.productName = productName;
this.productTime = productTime;
this.productTypeId = productTypeId;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductTime() {
return productTime;
}
public void setProductTime(String productTime) {
this.productTime = productTime;
}
public float getPrice() {
return price;
.addGap(23, 23, 23)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 221, Short.MAX_VALUE)
.addComponent(jButton2)
.addGap(90, 90, 90)))
.addGap(90, 90, 90))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(147, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel3))
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(priceTxt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
.addComponent(productNameTxt, javax.swing.GroupLayout.Alignment.TRAILING))
.addGap(59, 59, 59)
.addComponent(jLabel2)
.addGap(38, 38, 38)
.addComponent(productTimeTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(75, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(productTimeTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(productNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(priceTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(17, 17, 17)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jcb_ProductType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
jScrollPane1 = new javax.swing.JScrollPane();
productDescTxt = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
setTitle("\u5546\u54c1\u6dfb\u52a0");
jLabel1.setText("\u5546\u54c1\u540d\u79f0");
jLabel2.setText("\u751f\u4ea7\u65e5\u671f");
jLabel3.setText("\u4ef7\u683c");
jLabel4.setText("\u5546\u54c1\u7c7b\u522b");
jLabel5.setText("\u5546\u54c1\u63cf\u8ff0");
productDescTxt.setColumns(20);
productDescTxt.setRows(5);
jScrollPane1.setViewportView(productDescTxt);
jButton1.setIcon(new javax.swing.ImageIcon("./images\\add.png")); // NOI18N
jButton1.setText("\u6dfb\u52a0");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setIcon(new javax.swing.ImageIcon("./images\\reset.png")); // NOI18N
jButton2.setText("\u91cd\u7f6e");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
.addComponent(
jb_logon)
.addGap(
52,
52,
52)
.addComponent(
jb_reset))
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jLabel2)
.addComponent(
jLabel3))
.addGap(
35,
35,
35)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addComponent(
passwordTxt)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.DEFAULT_SIZE,
161,
Short.MAX_VALUE))))
.addGap(73, 73, 73)));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jLabel1)
jMenu4.add(jmiProductModify);
jMenu1.add(jMenu4);
jmiExit.setIcon(new javax.swing.ImageIcon(
"./images\\exit.png")); // NOI18N
jmiExit.setText("\u9000\u51fa\u7cfb\u7edf");
jmiExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmiExitActionPerformed(evt);
}
});
jMenu1.add(jmiExit);
jMenuBar1.add(jMenu1);
jMenu2.setIcon(new javax.swing.ImageIcon(
"./images\\about.png")); // NOI18N
jMenu2.setText("\u5173\u4e8e\u6211\u4eec");
jMenuItem6.setIcon(new javax.swing.ImageIcon(
"./images\\me.png")); // NOI18N
jMenuItem6.setText("\u5173\u4e8e\u7f51\u7ad9");
jMenu2.add(jMenuItem6);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(table,
javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(table,
javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE));
pack();
}// </editor-fold>
//GEN-END:initComponents
private void jmiProductModifyActionPerformed(java.awt.event.ActionEvent evt) {
ProductManageInterFrm ProductManageInterFrm = new ProductManageInterFrm();
ProductManageInterFrm.setVisible(true);
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ManagerLogOnFrm().setVisible(true);
}
});
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JButton jb_logon;
private javax.swing.JButton jb_reset;
private javax.swing.JPasswordField passwordTxt;
private javax.swing.JTextField userNameTxt;
// End of variables declaration//GEN-END:variables
}
/*
* CustomerAddInterFrm.java
*
* Created on __DATE__, __TIME__
*/
private void productTableMousePressed(java.awt.event.MouseEvent evt) {
//获取选中的行
int row = this.productTable.getSelectedRow();
this.idTxt.setText((Integer) productTable.getValueAt(row, 0) + "");
this.productNameTxt.setText((String) productTable.getValueAt(row, 1));
this.productTimeTxt.setText((String) productTable.getValueAt(row, 2));
this.priceTxt.setText((Float) productTable.getValueAt(row, 3) + "");
this.productDescTxt.setText((String) productTable.getValueAt(row, 4));
String productTypeName = (String) productTable.getValueAt(row, 5);
int n = this.jcb_productType.getItemCount();
for (int i = 0; i < n; i++) {
ProductType item = (ProductType) this.jcb_productType.getItemAt(i);
if (item.getProductTypeName().equals(productTypeName)) {
this.jcb_productType.setSelectedIndex(i);
}
}
this.jcb_productType.setEnabled(false);
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JTable ProductChosenTable;
private javax.swing.JTextField idTxt;
private javax.swing.JDialog jDialog1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JButton jb_cost;
private javax.swing.JButton jb_delete;
private javax.swing.JButton jb_putProductIntoCar;
private javax.swing.JButton jb_search;
private javax.swing.JComboBox jcb_productType;
private javax.swing.JTextField priceTxt;
private javax.swing.JTextArea productDescTxt;
private javax.swing.JTextField productNameTxt;
private javax.swing.JTable productTable;
private javax.swing.JTextField productTimeTxt;
private javax.swing.JComboBox s_jcbProductType;
private javax.swing.JTextField s_productNameTxt;
private javax.swing.JTextField s_productTimeTxt;
// End of variables declaration//GEN-END:variables
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addGap(14, 14, 14)
.addComponent(
jLabel5,
javax.swing.GroupLayout.DEFAULT_SIZE,
38, Short.MAX_VALUE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(27, 27, 27)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(
password1Txt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
try {
con = dbutil.getCon();
ResultSet rs = productTypeDao.productTypeList(con,
new ProductType());
if ("search".equals(type)) {
productType = new ProductType();
productType.setProductTypeName("请选择....");
productType.setId(-1);
this.s_jcbProductType.addItem(productType);
}
while (rs.next()) {
productType = new ProductType();
productType.setId(rs.getInt("id"));
productType.setProductTypeName(rs.getString("productTypeName"));
if ("search".equals(type)) {
this.s_jcbProductType.addItem(productType);
} else if ("modify".equals(type)) {
this.jcb_productType.addItem(productType);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
dbutil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private void fillTable(Product product) {
DefaultTableModel dtm = (DefaultTableModel) productTable.getModel();
dtm.setRowCount(0);//要把前面的数据释放掉
Connection con = null;
try {
con = dbutil.getCon();
ResultSet rs = productDao.productList(con, product);
while (rs.next()) {
Vector v = new Vector();
v.add(rs.getInt("id"));
v.add(rs.getString("productName"));
v.add(rs.getString("productTime"));
v.add(rs.getFloat("price"));
v.add(rs.getString("productDesc"));
v.add(rs.getString("productTypeName"));
52)
.addComponent(
jb_reset))
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jLabel2)
.addComponent(
jLabel3))
.addGap(
35,
35,
35)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addComponent(
passwordTxt)
.addComponent(
userNameTxt,
javax.swing.GroupLayout.DEFAULT_SIZE,
161,
Short.MAX_VALUE))))
.addGap(73, 73, 73)));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jLabel1)
.addGap(39, 39, 39)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
JOptionPane.showMessageDialog(null, "请选择要修改的记录");
return;
}
String productName = this.productNameTxt.getText();
String productTime = this.productTimeTxt.getText();
String price = this.priceTxt.getText();
String productDesc = this.productDescTxt.getText();
//取值后要判空
if (StringUtil.isEmpty(productName)) {
JOptionPane.showMessageDialog(null, " 商品名称不能为空!");
return;
}
if (StringUtil.isEmpty(productTime)) {
JOptionPane.showMessageDialog(null, " 生产日期不能为空!");
return;
}
if (StringUtil.isEmpty(price)) {
JOptionPane.showMessageDialog(null, " 价钱不能为空!");
return;
}
ProductType productType = (ProductType) this.jcb_productType
.getSelectedItem();
int productTypeId = productType.getId();
Product product = new Product(Integer.parseInt(id), productName,
productTime, Float.parseFloat(price), productDesc,
productTypeId);
Connection con = null;
try {
con = dbutil.getCon();
int modifyNum = productDao.productModify(con, product);
if (modifyNum == 1) {
JOptionPane.showMessageDialog(null, "修改成功");
this.resetValue();
this.fillTable(new Product());
} else {
JOptionPane.showMessageDialog(null, "修改失败");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null, "修改失败");
}finally{
try {
dbutil.closeCon(con);
private void jb_viewProductActionPerformed(java.awt.event.ActionEvent evt) {
new FuntionMainFrm().setVisible(true);
}
private void jb_ManagetLogOnActionPerformed(java.awt.event.ActionEvent evt) {
new ManagerLogOnFrm().setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ViewMainFrm().setVisible(true);
}
});
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JButton jb_ManagetLogOn;
private javax.swing.JButton jb_viewProduct;
// End of variables declaration//GEN-END:variables
}
/*
* FuntionMainFrm.java
*
* Created on __DATE__, __TIME__
*/
/**
*
*/
public class FuntionMainFrm extends javax.swing.JFrame {
/** Creates new form FuntionMainFrm */
public FuntionMainFrm() {
jLabel1.setFont(new java.awt.Font("微软雅黑", 0, 36));
jLabel1.setText("\u6b22\u8fce\u6765\u5230\u5546\u57ce");
jb_viewProduct.setText("\u6d4f\u89c8\u5546\u54c1");
jb_viewProduct.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_viewProductActionPerformed(evt);
}
});
jb_ManagetLogOn.setText("\u7ba1\u7406\u5458\u767b\u9646");
jb_ManagetLogOn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_ManagetLogOnActionPerformed(evt);
}
});
jButton3.setText("\u65b0\u4f1a\u5458\u6ce8\u518c");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_viewProductActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup().addContainerGap(111,
Short.MAX_VALUE).addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 301,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap()).addGroup(
layout.createSequentialGroup().addGap(27, 27, 27).addComponent(
jb_viewProduct).addGap(57, 57, 57).addComponent(
jb_ManagetLogOn).addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51,
Short.MAX_VALUE).addComponent(jButton3).addGap(22, 22,
22)));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(29, 29, 29)
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(table,
javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(table,
javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE));
pack();
}// </editor-fold>
//GEN-END:initComponents
private void jmi_customerAddActionPerformed(java.awt.event.ActionEvent evt) {
CustomerAddInterFrm CustomerAddInterFrm = new CustomerAddInterFrm();
CustomerAddInterFrm.setVisible(true);
this.table.add(CustomerAddInterFrm);
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
ProductBuyInterFrm productBuyInterFrm = new ProductBuyInterFrm();
productBuyInterFrm.setVisible(true);
this.table.add(productBuyInterFrm);
}
private void jmi_viewProductActionPerformed(java.awt.event.ActionEvent evt) {
ProductBuyInterFrm productBuyInterFrm = new ProductBuyInterFrm();
productBuyInterFrm.setVisible(true);
this.table.add(productBuyInterFrm);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FuntionMainFrm().setVisible(true);
}
});
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jmi_customerAdd;
private javax.swing.JMenu jmi_registerMember;
private javax.swing.JMenu jmi_viewProduct;