⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addbookmain.java

📁 java写的地址薄小程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            } else {                JOptionPane.showMessageDialog(this, "添加组失败请检查组名是否于其他组重复!!");            }            treeInitialize();            conn.close();        }    // TODO add your handling code here:    }//GEN-LAST:event_addGroup    private void addNewBook(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addNewBook        addNewBook();    // TODO add your handling code here:    }//GEN-LAST:event_addNewBook    public void addNewBook() {        new addNewBook(groupnameVe, userName).setVisible(true);    }    private void closing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closing        closing();    // TODO add your handling code here:    }//GEN-LAST:event_closing    public void closing() {        int i = JOptionPane.showConfirmDialog(this, "您确认要退出本系统吗?", "系统提示!!", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);        if (i == JOptionPane.YES_OPTION) {            System.exit(1);        }    }    private void modifyline(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modifyline        modifyline();    // TODO add your handling code here:    }//GEN-LAST:event_modifyline    public void modifyline() {        int row = jTable1.getSelectedRow();        try{             String name = (String) jTable1.getValueAt(row, 0);             new Modify(name, userName, groupnameVe).setVisible(true);                    }catch(IndexOutOfBoundsException ex){            JOptionPane.showMessageDialog(this,"请选定条目后再点击修改按钮!");        }           }    private void exitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitActionPerformed        closing();    // TODO add your handling code here:}//GEN-LAST:event_exitActionPerformed    private void removeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeActionPerformed        remove();    }//GEN-LAST:event_removeActionPerformed    public void remove() {        try {            int row = jTable1.getSelectedRow();            String name = (String) jTable1.getValueAt(row, 0);            int i = JOptionPane.showConfirmDialog(this, "此条目删除后将不可恢复请问要继续吗?", "系统提示", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);            if (i == JOptionPane.YES_OPTION) {                DabaCon conn = new DabaCon();                conn.condata();                if (conn.removeByName(name, userName)) {                    JOptionPane.showMessageDialog(this, "删除成功!!");                    refreah();                } else {                    JOptionPane.showMessageDialog(this, "删除失败!!!请重试!!");                }                conn.close();            }        } catch (IndexOutOfBoundsException ex) {            JOptionPane.showMessageDialog(this, "请从表中选择条目后再点击删除按钮!", "系统提示", JOptionPane.ERROR_MESSAGE);        }    }    private void refreah(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreah        refreah();    // TODO add your handling code here:    }//GEN-LAST:event_refreah    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed        closing();    // TODO add your handling code here:    }//GEN-LAST:event_jMenuItem4ActionPerformed    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed        addNewBook();    // TODO add your handling code here:    }//GEN-LAST:event_jMenuItem2ActionPerformed    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed        modifyline();    // TODO add your handling code here:    }//GEN-LAST:event_jMenuItem5ActionPerformed    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed        remove();    // TODO add your handling code here:    }//GEN-LAST:event_jMenuItem6ActionPerformed    private void removegroup(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removegroup        removegroup();          }//GEN-LAST:event_removegroup    private void treeChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_treeChanged        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent();        String group;        try {            group = selectedNode.toString();        } catch (NullPointerException ex) {            group = userName;        }        treeChanged(userName, group);    // TODO add your handling code here:    }//GEN-LAST:event_treeChanged    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed        findAction();    // TODO add your handling code here:    }//GEN-LAST:event_jMenuItem3ActionPerformed    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed        removegroup();    // TODO add your handling code here:    }//GEN-LAST:event_jMenuItem7ActionPerformed    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed        new aboutwin().setVisible(true);    // TODO add your handling code here:    }//GEN-LAST:event_jMenuItem8ActionPerformed    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed        new Login().setVisible(true);        this.dispose();    // TODO add your handling code here:    }//GEN-LAST:event_jMenuItem9ActionPerformed    public void treeChanged(String username, String group) {        Vector v;        DabaCon conn = new DabaCon();        conn.condata();        for (int i = count - 1; i >= 0; i--) {            model.removeRow(i);        }        if (userName.equals(group)) {            v = conn.select(userName);        } else {            v = conn.selcetbyGroup(userName, group);        }        Iterator ite = v.iterator();        count = 0;        while (ite.hasNext()) {            model.addRow((Vector) ite.next());            count++;        }        conn.close();    }    private void removegroup() {        try{        int i = JOptionPane.showConfirmDialog(this, "删除组后将无法恢复,请问要继续吗?", "系统提示", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);        if (i == JOptionPane.YES_OPTION) {            DabaCon con = new DabaCon();            con.condata();            String grouname = jTree1.getLastSelectedPathComponent().toString();            if (con.removegroup(userName, grouname)) {                JOptionPane.showMessageDialog(this, "删除成功!!");                treeChanged(userName, userName);                refreah();            } else {                JOptionPane.showMessageDialog(this, "删除失败!!根节点不能被删除!!!!");            }        }        }catch(NullPointerException ex){            JOptionPane.showMessageDialog(this, "请从左边窗口中选择组后再点击删除组按钮!", "系统提示", JOptionPane.ERROR_MESSAGE);        }    }    public void refreah() {        treeInitialize();        tableInitialize();    }    public void setUserName(String userName) {        this.userName = userName;    }    public String getUserName() {        return userName;    }    /**     * @param args the command line arguments     */    public void treeInitialize() {        DabaCon con = new DabaCon();        con.condata();        Vector v = con.selectgroup(userName);        groupnameVe = v;        root = new DefaultMutableTreeNode(getUserName());        DefaultMutableTreeNode groupname;        DefaultMutableTreeNode bookname;        Iterator it = v.iterator();        while (it.hasNext()) {            String gname = (String) it.next();            groupname = new DefaultMutableTreeNode(gname);            /* Vector book=con.selectgroup(gname);            Iterator i=book.iterator();            while(i.hasNext()){            bookname=new DefaultMutableTreeNode((String)i.next());            groupname.add(bookname);            }*/            root.add(groupname);        }        TreeModel treeModel = new DefaultTreeModel(root);//        jTree1.setModel(treeModel);        con.close();    }    public void tableInitialize(Vector v) {        count = 0;        String name[] = {"姓名", "邮箱", "手机", "地址", "分组"};        model = new DefaultTableModel(name, 0);        jTable1.setModel(model);        Iterator it = v.iterator();        while (it.hasNext()) {            Vector ve = (Vector) it.next();            model.addRow(ve);            count++;        }    }    public void tableInitialize() {        count = 0;        String name[] = {"姓名", "邮箱", "手机", "地址", "分组"};        model = new DefaultTableModel(name, 0);        jTable1.setModel(model);        DabaCon con = new DabaCon();        con.condata();        //userName="xingya771";        Vector v = con.select(userName);        Iterator it = v.iterator();        while (it.hasNext()) {            Vector ve = (Vector) it.next();            model.addRow(ve);            count++;        }        con.close();    }    public static void refrea() {    //new AddBookMain("xingya771").setVisible(true);    }    /* public static void main(String args[]) {    try {    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());    java.awt.EventQueue.invokeLater(new Runnable() {    public void run() {    AddBookMain abm = new AddBookMain("xingya771");    abm.setVisible(true);    }    });    } catch (ClassNotFoundException ex) {    Logger.getLogger(AddBookMain.class.getName()).log(Level.SEVERE, null, ex);    } catch (InstantiationException ex) {    Logger.getLogger(AddBookMain.class.getName()).log(Level.SEVERE, null, ex);    } catch (IllegalAccessException ex) {    Logger.getLogger(AddBookMain.class.getName()).log(Level.SEVERE, null, ex);    } catch (UnsupportedLookAndFeelException ex) {    Logger.getLogger(AddBookMain.class.getName()).log(Level.SEVERE, null, ex);    }    }*/    private Vector groupnameVe = new Vector();    private DefaultTableModel model;    private int count = 0;    private DefaultMutableTreeNode root;    // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JButton add;    private javax.swing.JButton exit;    private javax.swing.JButton find;    private javax.swing.JButton jButton1;    private javax.swing.JMenu jMenu1;    private javax.swing.JMenu jMenu2;    private javax.swing.JMenu jMenu3;    private javax.swing.JMenuBar jMenuBar1;    private javax.swing.JMenuItem jMenuItem1;    private javax.swing.JMenuItem jMenuItem2;    private javax.swing.JMenuItem jMenuItem3;    private javax.swing.JMenuItem jMenuItem4;    private javax.swing.JMenuItem jMenuItem5;    private javax.swing.JMenuItem jMenuItem6;    private javax.swing.JMenuItem jMenuItem7;    private javax.swing.JMenuItem jMenuItem8;    private javax.swing.JMenuItem jMenuItem9;    private javax.swing.JPanel jPanel1;    private javax.swing.JPanel jPanel2;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JScrollPane jScrollPane2;    private javax.swing.JSeparator jSeparator1;    private javax.swing.JSplitPane jSplitPane1;    private javax.swing.JTable jTable1;    private javax.swing.JToolBar jToolBar1;    private javax.swing.JTree jTree1;    private javax.swing.JButton modify;    private javax.swing.JButton refreah;    private javax.swing.JButton remove;    private javax.swing.JButton removegroup;    // End of variables declaration//GEN-END:variables}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -