1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public void drawNode(Graphics g, Noeud n, int x, int y) {
int textX, textY;
// on calcule textX et textY en fonction de x, y et de la taille du texte
// voir les classes Font et FontMetrics
...
g.drawString(n.getName(), textX, textY);
if(n.getRightChild() != null) {
g.drawLine(x + textHeight, y, x + 100, y + 100);
// moi je dis 100, 100 comme ça, ça pourrait être autre chose
drawNode(g, n.getRightChild(), x + 100, y + 100);
}
if(n.getLeftChild() != null) {
g.drawLine(x + textHeight, y, x - 100, y + 100);
drawNode(g, n.getLeftChild(), x - 100, y + 100);
}
} |
Partager