zoukankan      html  css  js  c++  java
  • Swing入门级项目全程实录第5讲

     惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧!

    1、增加控件jPanel、jTable、jTextField、jTextAreaField、jButton,修改相关属性及美化(略)
     
    2、鼠标点击事件
    private void jt_tableMousePressed(java.awt.event.MouseEvent evt) {
            int row=jt_table.getSelectedRow();
            jt_id.setText((String)jt_table.getValueAt(row, 0));
            jt_booktypename.setText((String)jt_table.getValueAt(row, 1));
            jt_booktypedesc.setText((String)jt_table.getValueAt(row, 2));
        }

    3、删除事件
      3.1删除方法

    public int bookTypemodefy(Connection con,BookType bookType) throws Exception{
            String sql="update t_booktype set bookTypeName=?,bookTypeDesc=? where id=?";
            PreparedStatement pstmt=con.prepareStatement(sql);
            pstmt.setString(1, bookType.getBookTypeName());
            pstmt.setString(2, bookType.getBookTypeDesc());
            pstmt.setInt(3, bookType.getId());
            return pstmt.executeUpdate();
        }

      3.2删除点击并清空表格

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            String id=jt_id.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=bookTypeDao.bookTypeDelete(con, id);
                    if(deleteNum==1){
                        JOptionPane.showMessageDialog(null, "删除成功");
                        fillTable(new BookType());
                        resetValue();
                    }else{
                        JOptionPane.showMessageDialog(null, "删除失败");
                    }
                    
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(null, "删除失败");
                }finally{
                    try {
                        dbUtil.closeCon(con);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }

    4修改事件

      4.1修改方法

    public int bookTypemodefy(Connection con,BookType bookType) throws Exception{
            String sql="update from t_booktype set bookTypeName=?,bookTypeDesc=? where id=?";
            PreparedStatement pstmt=con.prepareStatement(sql);
            pstmt.setString(1, bookType.getBookTypeName());
            pstmt.setString(2, bookType.getBookTypeDesc());
            pstmt.setInt(0, bookType.getId());
            return pstmt.executeUpdate();
        }

      4.2修改事件

        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            String id=jt_id.getText();
            String bookTypeName=jt_booktypename.getText();
            String bookTypeDesc=jt_booktypedesc.getText();
            if (StringUtil.isEmpty(id)) {
                JOptionPane.showMessageDialog(null, "请选择要修改的记录");
                return;
            }
            BookType bookType=new BookType(Integer.parseInt(id),bookTypeName,bookTypeDesc);
                Connection con = null;
                try {
                    con = dbUtil.getCon();
                    int modefyNum =bookTypeDao.bookTypemodefy(con, bookType);
                    if (modefyNum == 1) {
                        JOptionPane.showMessageDialog(null, "修改成功");
                        fillTable(new BookType());
                        resetValue();
                    } else {
                        JOptionPane.showMessageDialog(null, "修改失败");
                    }
    
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(null, "修改失败");
                } finally {
                    try {
                        dbUtil.closeCon(con);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
    
        }
  • 相关阅读:
    获取浏览器当前宽高
    获取当前页面一个 CSS 像素与一个物理像素之间的比率
    获取对象的所有属性,不管是否可遍历,不管是自身的还是原型链上的
    获取当前页面内所有框架窗口
    获取当前页面视口(viewport)宽高
    获取当前嵌入窗口所在的那个元素节点
    获取当前页面内框架窗口的数量
    获取窗口顶层对象
    获取当前窗口访问过的页面的数量
    获取`script`标签中的代码内容
  • 原文地址:https://www.cnblogs.com/cnmotive/p/3129539.html
Copyright © 2011-2022 走看看