codice:
public class NodoTreeLabel extends JLabel {
private int dimensionex,dimensioney;
private String testo;
int a,b,h,w,x,y;
public NodoTreeLabel(String testo,int dimensionex, int dimensioney){
super();
this.testo=testo;
this.dimensionex=dimensionex;
this.dimensioney=dimensioney;
x=dimensionex/2;
y=dimensioney/8;
h=dimensioney/8;
w=dimensionex/8;
a=dimensionex/4;
b=a*3;
}
@Override
public void paint(Graphics g){
super.paint(g);
drawNodes(g, g.getFontMetrics(), x, y);
p(g,a,b,x,y);
p(g, a+w, a-w, a, y+h);
p(g, b+w, b-w, b, y+h);
}
private void p(Graphics g,int a,int b,int x,int y){
drawNodes(g, g.getFontMetrics(), a, y+h);
g.drawLine(x+5, y+10, a, y+h);
drawNodes(g, g.getFontMetrics(), b, y+h);
g.drawLine(x-5, y+10, b, y+h);
}
private void drawNodes(Graphics bg, FontMetrics fontmetrics,int ascisse,int ordinate) {
int k = fontmetrics.stringWidth(testo) + 10;
int l = fontmetrics.getHeight() + 4;
Color color;
Graphics2D g=(Graphics2D)bg;
g.setColor(Color.LIGHT_GRAY);
g.fillOval(ascisse - k / 2, ordinate - l / 2, k, l);
// g.setColor(Color.BLUE);
g.drawOval(ascisse - k / 2, ordinate - l / 2, k - 1, l - 1);
g.setColor(Color.black);
g.drawString(testo, ascisse - (k - 10) / 2, (ordinate - (l - 4) / 2) + fontmetrics.getAscent());
g.setColor(Color.LIGHT_GRAY);
}
}
dovrei cercare di estrapolare l'algortmo per mettere le coordinate in automatotico passando stringe contenenti quello che voglio stampare