I have a binary tree and I need to display it in an applet. I was going to drawString for the root and then for the next line I was going to drawLine going left, skip some space, and draw a line to the right. Then on the next line I drawString for each child of the root. and so on so forth. But if the child is null...no line or string is drawn. I'm thinking I got to do a breadth first traversal, put each name in a queue, dequeue it and draw the necessary things. However, I can't get anywhere with drawing this tree.
There are some GraphLayout examples in the demo folder of your sdk that show one way of showing a tree graph (sdk1.5/demo/plugin/applets/GraphLayout). There may be a number of ways of setting this up. One way I did this was to use the tree nodes to make up a set of graphNodes to be used for drawing. Make up a new set of graphNodes for each addition/removal of a node in your tree. Each of these graphNodes can keep an x, y location for itself and for each child. Use these to draw the graphNode and a line to each child as you move through the graphNodes. Use your binary tree methods to help figure out the location of each graphNode relative to its parent node on up to the tree root node. Then you can run through the graphNodes and calculate the width and height of the tree graph and use this to locate/center (and draw) the tree in your gui graphic component and to set the scrollbars on its parent JScrollPane.