I am trying to write an integer number inside the graphic figure and want it positioning to always be at the center.
Is there any way to do so?
Currently I am writing this which is not good :
Font font = new Font("Arial", Font.BOLD, 20);
g.setFont(font);
g.setColor(this.color);
g.fillOval(b.x, b.y, b.width, b.height);
g.setColor(Color.black);
g.drawString("1", b.x + b.width/2 , b.y+ b.height/2);
where b is a rectangle.
You can use the FontMetrics class to determine the exact size of the String you want to display, and then subtract half its X and Y dimensions from your center point, and draw it there, like this: