——————————DescriptionStart——————————
运行环境 Java≥8、MySQL≥5.7
开发工具 eclipse/idea/myeclipse/sts等均可配置运行
适用 课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于java的Swing+MySQL购物商城(java+swing+mysql+gui)
1 2 3 4 5 6 管理员登录:ManagerLogOnFrm admin 123456 用户购物:FuntionMainFrm user1 123456 user2 123456
——————————CodeStart——————————
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 } public void setCustomerName (String customerName) { this .customerName = customerName; } public String getPassword1 () { return password1; } public void setPassword1 (String password1) { this .password1 = password1; } public String getPassword2 () { return password2; } public void setPassword2 (String password2) { this .password2 = password2; } public float getMoney () { return money; } public void setMoney (float money) { this .money = money; } } public class Dbutil { private String dbUrl = "jdbc:mysql://localhost:3306/project?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull" ; private String dbUserName = "root" ; private String dbPassword = "123456" ; private String jdbcName = "com.mysql.jdbc.Driver" ; public Connection getCon () throws Exception { Class.forName(jdbcName); Connection Con = DriverManager.getConnection(dbUrl, dbUserName, dbPassword); return Con; }
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 public class CustomerLogOnInterFrm extends javax .swing .JInternalFrame { Dbutil dbUtil = new Dbutil(); CustomerUserDao customerUserDao = new CustomerUserDao(); public CustomerLogOnInterFrm () { initComponents(); } private void initComponents () { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); userNameTxt = new javax.swing.JTextField(); passwordTxt = new javax.swing.JPasswordField(); jb_logon = new javax.swing.JButton(); jb_reset = new javax.swing.JButton(); setClosable(true ); setIconifiable(true ); addAncestorListener(new javax.swing.event.AncestorListener() { public void ancestorMoved (javax.swing.event.AncestorEvent evt) { } public void ancestorAdded (javax.swing.event.AncestorEvent evt) { formAncestorAdded(evt); } public void ancestorRemoved (javax.swing.event.AncestorEvent evt) { } }); jLabel1.setFont(new java.awt.Font("微软雅黑" , 0 , 18 ));
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 javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( productTypeNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( jPanel1Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4) .addComponent( jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 88 , javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18 , 18 , 18 ) .addGroup( jPanel1Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jb_modify) .addComponent(jb_delete)) .addGap(32 , 32 , 32 ))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout( getContentPane()); getContentPane().setLayout(layout); layout .setHorizontalGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addGap(46 , 46 , 46 ) .addComponent(jLabel1) .addGap(41 , 41 , 41 ) .addComponent( s_ProductTypeNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 145 , javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED,
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 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) { e.printStackTrace(); JOptionPane.showMessageDialog(null , "修改失败" ); }finally { try { dbutil.closeCon(con); } catch (Exception e) { e.printStackTrace(); } } } private void jButton2ActionPerformed (java.awt.event.ActionEvent evt) { String id = this .idTxt.getText(); if (StringUtil.isEmpty(id)) { JOptionPane.showMessageDialog(null , "请选择要删除的数据" ); return ; } int n = JOptionPane.showConfirmDialog(null , "确定要删除这条数据吗?" ); if (n == 0 ) { Connection con = null ; try { con = dbutil.getCon(); int deleteNum = productDao.productDelete(con, id); if (deleteNum == 1 ) { JOptionPane.showMessageDialog(null , "删除成功" ); this .resetValue(); this .fillTable(new Product()); } else { JOptionPane.showMessageDialog(null , "删除失败" ); }
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 pack(); }// </editor-fold > //GEN-END:initComponents private void jb_AddActionPerformed(java.awt.event.ActionEvent evt) { String productTypeName=this.productTypeNameTxt.getText(); String productTypeDesc=this.productTypeDescTxt.getText(); //要使用Util语句前要先在开头创个Dbutil的对象,同理也要引进Dao对象 if(StringUtil.isEmpty(productTypeName)){ JOptionPane.showMessageDialog(null, "商品类别不能为空"); return; } ProductType productType=new ProductType(productTypeName, productTypeDesc); Connection con=null; try { con=dbutil.getCon(); int n=productTypeDao.productTypeAdd(con, productType); if(n==1){ JOptionPane.showMessageDialog(null,"商品类别添加成功"); this.resetValues(); }else{ JOptionPane.showMessageDialog(null,"商品类别添加失败"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); JOptionPane.showMessageDialog(null,"商品类别添加失败"); } } private void jb_resetActionPerformed(java.awt.event.ActionEvent evt) { this.resetValues(); } private void resetValues() { this.productTypeNameTxt.setText(""); this.productTypeDescTxt.setText(""); } //GEN-BEGIN:variables // Variables declaration - do not modify private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1;
——————————PayStart——————————
项目链接: https://javayms.github.io?id=471223162708201bx https://javayms.pages.dev?id=471223162708201bx