import javax.swing.JFrame; 
import java.awt.Graphics;
import java.awt.Color;

public class BST {
  int x, y; 
  int depth; // y is 50 + depth (maybe) 
  // depth also controls the longitude 
  int value; 
  BST left, right; 
  // ------------------------------------------------------( data representation )------------------
  public BST(int value, BST left, BST right) {
    this.value = value; 
    this.left = left; 
    this.right = right; 
  }
  // ------------------------------------------------------( constructor )------------------
  public boolean searchFor(int value) {
    if (this.value == value) 
      return true; 
    if (this.value > value) {
      if (this.left == null) return false; 
      else return this.left.searchFor(value); 
    } else {
      if (this.right == null) return false; 
      else return this.left.searchFor(value); 
    }
  }
  // ------------------------------------------------------( one method )------------------
  public boolean insert(int value) {
    if (this.value == value) 
      return false; 
    if (this.value > value) {
      if (this.left == null) {
        this.left = new BST(value, null, null); 
        return true; 
      } else return this.left.insert(value); 
    } else {
      if (this.right == null) {
         this.right = new BST(value, null, null); 
         return true; 
      } else return this.right.insert(value); 
    }      
  }
  public void draw(Graphics g) {
    g.setColor(Color.WHITE); 
    g.fillOval(this.x, this.y, 40, 40);  
    g.setColor(Color.BLACK); 
    g.drawOval(this.x, this.y, 40, 40);  
    g.drawString(this.value + "", this.x + 40 / 2 - 5, this.y + 40 / 2 + 5); 
    if (this.left == null) {
      
    } else this.left.draw(g);
    if (this.right == null) {
      
    } else this.right.draw(g); 
  }
  // ------------------------------------------------------( another method )------------------
  public static void main(String[] args) {
    BST a = new BST( 8, new BST( 3, new BST(1, null, 
                                               null), 
                                    new BST(6, null, 
                                               null)), 
                        new BST(10, null, 
                                    new BST(14, null, 
                                                null)));
    a.x = 200; a.y = 0; 
    a.left.x        = 100; a.left.y        = 100; // 3 
    a.right.x       = 300; a.right.y       = 100; // 10 
    a.right.right.x = 350; a.right.right.y = 200; // 14
    a.left.left.x   =  50; a.left.left.y   = 200; // 1 
    a.left.right.x  = 150; a.left.right.y  = 200; // 6
    JFrame f = new JFrame("Exercise"); 
    Drawing d = new Drawing(a); 
    f.add(d); 
    f.setVisible(true); 
    f.setSize(400, 400); 
  }
}

--

import javax.swing.JComponent; 
import java.awt.Graphics; 

public class Drawing extends JComponent {
  BST bst; 
  public Drawing(BST bst) {
    this.bst = bst;     
  }
  public void paintComponent(Graphics g) {
    this.bst.draw(g); 
  }
}

--