📄 outlinemltree.java
字号:
/* * * outlineMlTree.java * * an extension of outline.class using the Microline * Component Toolkit tree 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 mlsoft.mct.*;import java.awt.*;import java.sql.*;class outlineMlTree extends outline implements MlTreeListener { MlTree tree; /** * * Constructs a new outlineMlTree 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 outlineMlTree (String url, String user, String pwd, MlTree t) { super(url, user, pwd); tree = t; } /** * * 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) { tree.setValue("layoutFrozen", true); tree.addRow(level, children > 0, label); tree.setValue("layoutFrozen", false); } /** * * 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 outlineMlTree 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 myFrame object that knows how to close itself // myFrame f = new myFrame(); f.setLayout(new BorderLayout()); // create an MlTree object and add it to the frame // MlTree tree = new MlTree(); tree.setValue("layoutFrozen", false); f.add("Center", tree); tree.setValue("layoutFrozen", true); tree.addRow(0, true,"Root"); tree.addRow(1, true, "Level 1 Parent"); tree.addRow(2, false,"1st Child of Level 1 Parent"); tree.addRow(2, false,"2nd Child of Level 1 Parent"); tree.addRow(2, true, "Level 2 Parent"); tree.addRow(3, false, "Child of Level 2 Parent"); tree.addRow(1, true, "Level 1 Parent"); tree.addRow(2, false, "Child of Level 1 Parent"); tree.setValue("layoutFrozen", false); // resize and show the frame // f.setSize(400, 300); f.show(); // instantiate the outlineMlTree object and traverse it // //outlineMlTree tr = new outlineMlTree(argv[0], user, pwd, tree); //tr.traverseTree("tree", "tree_id", "parent_id", "name"); } public void onTreeEvent(MlTreeEvent event) { if (event.getType() == MlTreeEvent.SELECT_ACTIVATED) { System.out.println("row " + event.row + " activated"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -