how can i add a permenent button to the inthalizingg tree panel import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class BinaryTreeBuilder extends JPanel {
    private static final int NODE_SIZE = 30;
    private static final int LEVEL_HEIGHT = 70;
    private Node root;
    

    public BinaryTreeBuilder() {
        setPreferredSize(new Dimension(800, 600));
        setLayout(null);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        removeAll(); // Remove all existing buttons
        if (root != null) {
            drawTree(g, root, getWidth() / 2, 30, getWidth() / 4);
        }
    }

    private void drawTree(Graphics g, Node node, int x, int y, int xOffset) {
        g.setColor(Color.BLACK);
        g.fillOval(x - NODE_SIZE / 2, y - NODE_SIZE / 2, NODE_SIZE, NODE_SIZE);
        g.setColor(Color.WHITE);
        g.drawString(node.getName(), x - 5, y + 5);

        if (node.getLeft() == null) {
            JButton addLeftButton = createAddButton("Add L");
            addLeftButton.setBounds(x - xOffset - 30, y + LEVEL_HEIGHT / 2, 60, 20);
            add(addLeftButton);
            addLeftButton.addActionListener(e -> showAddNodeDialog(node, true));
        } else {
            g.setColor(Color.BLACK);
            g.drawLine(x, y, x - xOffset, y + LEVEL_HEIGHT);
            drawTree(g, node.getLeft(), x - xOffset, y + LEVEL_HEIGHT, xOffset / 2);
        }

        if (node.getRight() == null) {
            JButton addRightButton = createAddButton("Add R");
            addRightButton.setBounds(x + xOffset - 30, y + LEVEL_HEIGHT / 2, 60, 20);
            add(addRightButton);
            addRightButton.addActionListener(e -> showAddNodeDialog(node, false));
        } else {
            g.setColor(Color.BLACK);
            g.drawLine(x, y, x + xOffset, y + LEVEL_HEIGHT);
            drawTree(g, node.getRight(), x + xOffset, y + LEVEL_HEIGHT, xOffset / 2);
        }
    }

    private JButton createAddButton(String text) {
        JButton button = new JButton(text);
        button.setBackground(new Color(173, 216, 230));
        button.setFocusPainted(false);
        button.setMargin(new Insets(2, 5, 2, 5));
        return button;
    }

      void showAddNodeDialog(Node parent, boolean isLeft) {
        JTextField nameField = new JTextField();
        JTextField widthField = new JTextField();
        JTextField heightField = new JTextField();

        Object[] message = {
                "Name:", nameField,
                "Width:", widthField,
                "Height:", heightField
        };
        int option = JOptionPane.showConfirmDialog(null, message, "Enter Node Data", JOptionPane.OK_CANCEL_OPTION);
        if (option == JOptionPane.OK_OPTION) {
            String name = nameField.getText();
            int width, height;
            try {
                width = Integer.parseInt(widthField.getText());
                height = Integer.parseInt(heightField.getText());
            } catch (NumberFormatException e) {
                JOptionPane.showMessageDialog(null, "Invalid width or height", "Error", JOptionPane.ERROR_MESSAGE);
                showAddNodeDialog(parent,isLeft);
                return;
            }
            BinaryTreeDrawer.drawBinaryTree(this.root);
            Node newNode = new Node(name, width, height);
            if (isLeft) {
                parent.setLeft(newNode);
            } else {
                parent.setRight(newNode);
            }
            repaint();
        }
    }

    public static Node insertTree() {
        JFrame frame = new JFrame("Binary Tree Builder");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        BinaryTreeBuilder panel = new BinaryTreeBuilder();
        frame.add(panel);
        boolean b=true;
        while(b){
        JTextField rootNameField = new JTextField();
        JTextField rootWidthField = new JTextField();
        JTextField rootHeightField = new JTextField();

        Object[] rootMessage = {
                "Root Name:", rootNameField,
                "Root Width:", rootWidthField,
                "Root Height:", rootHeightField
        };

        int rootOption = JOptionPane.showConfirmDialog(null, rootMessage, "Enter Root Data", JOptionPane.OK_CANCEL_OPTION);
        if (rootOption == JOptionPane.OK_OPTION) {
            String rootName = rootNameField.getText();
            int rootWidth, rootHeight;
            try {
                rootWidth = Integer.parseInt(rootWidthField.getText());
                rootHeight = Integer.parseInt(rootHeightField.getText());
                b=false;
            } catch (NumberFormatException e) {

                JOptionPane.showMessageDialog(null, "Invalid root width or height", "Error", JOptionPane.ERROR_MESSAGE);
                continue;
            }

            panel.root = new Node(rootName, rootWidth, rootHeight); // Initial root node
        }
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
        return null;
    }
}