我想在Java GUI中顯示一棵樹,但我不知道如何。該樹表示連接節點的圖形,像這樣:如何繪製代表連接節點圖的樹?
我應該說,我有我自己的樹類:
public class BinaryTree
{
private BinaryNode root;
public BinaryTree()
{
root = null;
}
public BinaryTree(Object rootItem)
{
root = new BinaryNode(rootItem, null, null);
}
public BinaryTree(Object rootItem,BinaryNode a,BinaryNode b)
{
root = new BinaryNode(rootItem, a, b);
}
public int leavesCount(){
return BinaryNode.leavesCount(root);
}
public boolean equal(BinaryTree a,BinaryTree b){
return BinaryNode.equal(a.root, b.root);
}
public void printPreOrder()
{
if(root != null)
root.printPreOrder();
}
public void printInOrder()
{
if(root != null)
root.printInOrder();
}
public void printPostOrder()
{
if(root != null)
root.printPostOrder();
}
public void makeEmpty()
{
root = null;
}
public boolean isEmpty()
{
return root == null;
}
public void merge(Object rootItem, BinaryTree t1, BinaryTree t2) throws MergeAbrot
{
if(t1.root == t2.root && t1.root != null)
{
throw new MergeAbrot("MergeAbrot");
}
root=new BinaryNode(rootItem, t1.root, t2.root);
if(this != t1)
t1.root = null;
if(this != t2)
t2.root = null;
}
public int size()
{
return BinaryNode.size(root);
}
public int height()
{
return BinaryNode.height(root);
}
}
我只想繪製樹。我應該怎麼做?
sry但我想顯示樹這樣的鏈接:lcm.csa.iisc.ernet.in/dsa/img151.gif – Oli 2012-04-12 15:37:03
不知道是否有免費的圖書館來建立這樣的視覺樹。您可以隨時使用基本的圖形工具自行繪製它。 – 2012-04-12 15:44:51