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

📄 outlinejtree.java

📁 有关JDBC的使用一些编程实例,有关与数据库连接的代码
💻 JAVA
字号:
/* * * outlineJTree.java * * an extension of outline.class using the JFC (Swing) JTree component. * * Copyright 1996 John Wiley & Sons, Inc. All Rights Reserved. Reproduction * or translation of this work beyond that permitted in Section 117 of the 1976 * United States Copyright Act without the express written permission of the * copyright owner is unlawful. Requests for further information should be  * addressed to Permissions Department, John Wiley & Sons, Inc. The  * purchaser may make back-up copies for his/her own use only and not for  * distribution or resale. The Publisher assumes no responsibility for errors,  * omissions, or damages, caused by the use of this  software or from the use * of the information contained herein. * */import com.sun.java.swing.*;import com.sun.java.swing.text.*;import com.sun.java.swing.tree.*;import java.awt.event.*;import java.util.*;import java.awt.*;import java.sql.*;class outlineJTree extends outline {  JTree tree;  DefaultMutableTreeNode top = new DefaultMutableTreeNode("");;  Stack node_stack = new Stack();  int curr_level = 1;  /**   *   * Constructs a new outlineJTree object.   * @param url a URL to  a valid JDBC data source.   * @param user a username   * @param pwd a password   * @param t an MlTree object   *   */  public outlineJTree (String url, String user, String pwd) {    super(url, user, pwd);    node_stack.push(top);  }  DefaultMutableTreeNode getTop() {      return top;  }  /**   *   * addNode()   *   * This subclasses the addNode() method in outline.class to   * use an MlTree   *   * @param level the level within the tree (starts at 1)   * @param children the number of children   * @param label the text of the item   *   */  void addNode (int level, int children, String label) {    // Pop the stack until we are sitting on this node's parent.    //    for (int i = curr_level; i > level; i--) {            node_stack.pop();    }    // Create the new node.    //    DefaultMutableTreeNode new_node = new DefaultMutableTreeNode(label);    // Get the parent of this node from the stack.    //    DefaultMutableTreeNode current =         (DefaultMutableTreeNode) node_stack.peek();    // Add the new node to the parent node.    //    current.add(new_node);    // If this node has children, add it to the stack of nodes.    //    if (children != 0) {        node_stack.push(new_node);    }    // Save the current level of this node.    //    curr_level = level;  }  /**   *    * instantiate the outline object with test data.   *   */  public static void main (String argv[]) {    if (argv.length == 0) {    	System.out.println("You must supply a URL to a JDBC data source.");    	System.out.println("");    	System.out.println("Example:");    	System.out.println("java outlineJTree jdbc:odbc:DATA_SOURCE_NAME;" +	                   "UID=userid;PWD=password");      System.exit(0);    }    // the user might have passed in a user name or password,    // so try to read those in, as well    //    String user, pwd;    if (argv.length > 1) {      user = argv[1];    } else {      user = "";    }    if (argv.length > 2) {      pwd = argv[2];    } else {      pwd = "";    }    // create a Frame.    //    Frame f = new Frame();    // Set up a WindowAdapter that can close the Frame when the user clicks    // on the close control.    //    f.addWindowListener(new WindowAdapter() {        public void windowClosing(WindowEvent e) {            System.exit(0);        }    });    // Set the Frame's layout.    //    f.setLayout(new BorderLayout());    // instantiate the outlineJTree object and traverse it    //    outlineJTree tr = new outlineJTree(argv[0], user, pwd);    tr.traverseTree("tree", "tree_id", "parent_id", "name");    JTree tree = new JTree(tr.getTop());    f.add("Center", tree);    f.setSize(400, 300);    f.show();      }}

⌨️ 快捷键说明

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