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

📄 musiclistview.java~118~

📁 音乐播放器 好像是用java编的 欢迎下载
💻 JAVA~118~
📖 第 1 页 / 共 2 页
字号:
    }

    public void update(Observable o, Object arg)
    {
   //     System.out.println("In update");
        MusicModel mm = (MusicModel)o;
        DefaultMutableTreeNode mmnode = null;
        if (rootNode.getChildCount() >= 0)
        {
            for (Enumeration e=rootNode.children(); e.hasMoreElements(); )
            {
                DefaultMutableTreeNode n = (DefaultMutableTreeNode)e.nextElement();
                if(n.toString().equals(mm.getName()))
                {
                    mmnode = n;
                    break;
                }
            }
        }

    /*    if(mmnode == null)
        {
            System.out.println("mmnode not found!");
            return;
        }
   */
        mmnode.removeAllChildren();
        treeModel.reload();


        DefaultMutableTreeNode music = null;
        String DRIVER = "com.borland.datastore.jdbc.DataStoreDriver";
        String URL = "jdbc:borland:dslocal:";
        String FILE = "musicmgrsys.jds";

        try
        {
            Class.forName(DRIVER);
            Connection con = DriverManager.getConnection(URL + FILE, "SYSDBA",
                                                         "masterkey");
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("select TITLE from " + mm.getTabname());

            while(rs.next())
            {
                this.addObject(mmnode, rs.getString("TITLE"));
            }

            rs.close();
            stmt.close();
            con.close();
        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(null, ex.toString());
        }
}

    private void readObject(ObjectInputStream ois) throws IOException,
            ClassNotFoundException {
        ois.defaultReadObject();
    }

    private void writeObject(ObjectOutputStream oos) throws IOException {
        oos.defaultWriteObject();
    }

    public void removeCurrentNode() {
        TreePath currentSelection = jTree1.getSelectionPath();
        if (currentSelection != null) {
            DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode)
                         (currentSelection.getLastPathComponent());
            MutableTreeNode parent = (MutableTreeNode)(currentNode.getParent());
            if (parent != null) {
                treeModel.removeNodeFromParent(currentNode);
                return;
            }
        }

        // Either there was no selection, or the root was selected.
        toolkit.beep();
    }

    public DefaultMutableTreeNode addObject(Object child) {
            DefaultMutableTreeNode parentNode = null;
            TreePath parentPath = jTree1.getSelectionPath();

            if (parentPath == null) {
                parentNode = rootNode;
            } else {
                parentNode = (DefaultMutableTreeNode)
                             (parentPath.getLastPathComponent());
            }

            return addObject(parentNode, child, true);
        }

        public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
                                                Object child) {
            return addObject(parent, child, false);
        }

        public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
                                                Object child,
                                                boolean shouldBeVisible) {
            DefaultMutableTreeNode childNode =
                    new DefaultMutableTreeNode(child);

            if (parent == null) {
                parent = rootNode;
            }

            treeModel.insertNodeInto(childNode, parent,
                                     parent.getChildCount());

            //Make sure the user can see the lovely new node.
            if (shouldBeVisible) {
                jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));
            }
            return childNode;
    }
}

class MyTreeModelListener implements TreeModelListener {
        MusicListView mlv = null;

        public MyTreeModelListener(MusicListView mlv)
        {
            this.mlv = mlv;
        }

        public void treeNodesChanged(TreeModelEvent e) {
            DefaultMutableTreeNode node;
            node = (DefaultMutableTreeNode)
                     (e.getTreePath().getLastPathComponent());

            /*
             * If the event lists children, then the changed
             * node is the child of the node we've already
             * gotten.  Otherwise, the changed node and the
             * specified node are the same.
             */
            try {
                int index = e.getChildIndices()[0];
                node = (DefaultMutableTreeNode)
                       (node.getChildAt(index));
            } catch (NullPointerException exc) {}
            if (mlv.getTree().getPathForLocation(mlv.getX(), mlv.getY()).getPathCount() == 2)
            {
                String DRIVER = "com.borland.datastore.jdbc.DataStoreDriver";
                String URL = "jdbc:borland:dslocal:";
                String FILE = "musicmgrsys.jds";

                try
                {
                    Class.forName(DRIVER);
                    Connection con = DriverManager.getConnection(URL + FILE, "SYSDBA",
                                                         "masterkey");
                    Statement stmt = con.createStatement();
                    stmt.executeUpdate("Update MUSICSET set NAME='" + node.getUserObject() + "'" + " where NAME='" + mlv.getNodeStr() + "'");
                    stmt.close();
                    con.close();
                }
                catch(Exception ex)
                {
                    JOptionPane.showMessageDialog(null, ex.toString());
                }

            }
            else if(mlv.getTree().getPathForLocation(mlv.getX(), mlv.getY()).getPathCount() == 3)
            {
                String setName = mlv.getTree().getPathForLocation(mlv.getX(), mlv.getY()).getParentPath().
                                  getLastPathComponent().toString();
                //System.out.println(setName);
                String tabName = null;
                String DRIVER = "com.borland.datastore.jdbc.DataStoreDriver";
                String URL = "jdbc:borland:dslocal:";
                String FILE = "musicmgrsys.jds";

                try
                {
                    Class.forName(DRIVER);
                    Connection con = DriverManager.getConnection(URL + FILE, "SYSDBA",
                                                         "masterkey");
                    Statement stmt = con.createStatement();
                    ResultSet rs = stmt.executeQuery("select TABNAME from MUSICSET where NAME='" + setName + "'");
                    while(rs.next())
                    {
                        tabName = rs.getString("TABNAME");
                    }
                    rs.close();
                    stmt.executeUpdate("Update " + tabName + " set TITLE='" + node.getUserObject() + "' where TITLE='" + mlv.getNodeStr() + "'");
                   // System.out.println("Update " + tabName + " set TITLE='" + node.getUserObject() + "' where TITLE='" + mlv.getNodeStr() + "'");
                    Statement stmt1 = con.createStatement();
                    ResultSet rs1 = stmt1.executeQuery("select * from " + tabName + " where TITLE='" + node.getUserObject() + "'");
                    JTextArea jta = mlv.mv.getMusicItemView().getTextArea();
                    while(rs1.next())
                    {
                         jta.setText("");
                         jta.append("格式: " + rs1.getString("FORMAT") + "\n");
                         jta.append("种类: " + rs1.getString("GERUE") + "\n");
                         jta.append("等级: " + rs1.getString("RATING") + "\n");
                         jta.append("评价: " + rs1.getString("EVALUATION") + "\n");
                         jta.append("标题: " + rs1.getString("TITLE") + "\n");
                         jta.append("原唱: " + rs1.getString("DIRECTOR") + "\n");
                         jta.append("年份: " + rs1.getString("YEAR") + "\n");
                         jta.append("注释: " + rs1.getString("COMMENTS") + "\n");
                         jta.append("路径: " + rs1.getString("LOCATION") + "\n");

                    }
                    rs1.close();
                    stmt1.close();
                    stmt.close();
                    con.close();
                }
                catch(Exception ex)
                {
                    JOptionPane.showMessageDialog(null, ex.toString());
                }

            }
        }
        public void treeNodesInserted(TreeModelEvent e) {
        }
        public void treeNodesRemoved(TreeModelEvent e) {
        }
        public void treeStructureChanged(TreeModelEvent e) {
        }
  }

⌨️ 快捷键说明

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