TWaver基于swing的应用--树

package com;
import java.awt.*;

import javax.swing.*;

import twaver.*;
import twaver.network.*;
import twaver.tree.*;

public class DummyDemo extends JFrame {
	
	//BorderLayout bo=new BorderLayout();
	//创建数据箱、树图和地图
    TDataBox box = new TDataBox("机房");
    TTree tree = new TTree(box);
    TNetwork network=new TNetwork(box);
    private JPanel treePane = new JPanel(new BorderLayout());
    public DummyDemo() {
        this.getContentPane().add(network, BorderLayout.CENTER);		
        this.setSize(700, 700);
        //创建网元方法
        loadData();
        //下边布置树的显示 ---只需要把new出的tree放进JScrollPane中,
        //然后将JScrollPane和network放入JSplitPane中进行分割页面的布局
        tree.setEnsureVisibleOnSelected(true);     
        JScrollPane scroll = new JScrollPane(tree);
        treePane.add(scroll, BorderLayout.CENTER);
        JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treePane, network);
        split.setDividerLocation(180);        
        this.add(split);
        
    }

private void loadData() {
    //创建网元
        Node atm1 = new Node();
        atm1.setName("ATM1");
        atm1.setLocation(100, 100);
        box.addElement(atm1);
        Node atm2 = new Node();
        atm2.setName("ATM2");
        atm2.setLocation(200, 100);
        box.addElement(atm2);
        Node sdh1 = new Node();
        sdh1.setName("SDH1");
        sdh1.setLocation(100, 200);
        box.addElement(sdh1);
        Node sdh2 = new Node();
        sdh2.setName("SDH2");
        sdh2.setLocation(200, 200);
        box.addElement(sdh2);
    //创建Dummy(树的节点)对象进行分组
        Dummy atm=new Dummy();
        
        atm.setName("交换设备");
        atm.addChild(atm1);
        atm.addChild(atm2);
        box.addElement(atm);
        Dummy sdh=new Dummy();
        sdh.setName("传输设备");
        sdh.addChild(sdh1);
        sdh.addChild(sdh2);
        box.addElement(sdh);
    }

    public static void main(String[] args) throws Exception {
        DummyDemo test = new DummyDemo();
        test.show();
    }
}

 

你可能感兴趣的:(swing)