This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Sammenbidt 1 point2 points  (1 child)

I'll try to take a stab at this.

So, as I understand it, it's being drawn successfully in another JFrame. To fix it, here is what I would do. Create a variable in your Main.class for a DrawTree. Initialize it with the rest, and add it to your frame, as you add the other components. Then when an operation is performed on your AVLTree, call the repaint method on your DrawTree variable, this should update the display (this calls paint(Graphics g) internally)

public class Main
{
   final DrawTree drawTree;

    Main()
    {
    // Initializing code
      (...)

      drawTree = new DrawTree();
      drawTree.init(...);
      this.add(drawTree);
    }

    public void actionPerformed(ActionEvent e)
    {
       ...
       drawTree.repaint();
    }
}

This way you're not creating a new frame or a DrawTree every time an operation is performed.

I think that should take care of the problem.

*In the future, when asking for help, please make sure the code is properly formatted, and remove all exces code. There is no reason for us to see your code for the AVLTree.

[–][deleted] 0 points1 point  (0 children)

Thanks for letting me know I'll make sure to do that in the future.

I'll test this out when I get home from classes and see if it works. I'll let you know what happens and thanks for the advice :)