title: Positioning string in graphic + java
body: <p>I am trying to write an integer number inside the graphic figure and want it positioning to always be at the center.</p>
  
  <p>Is there any way to do so?</p>
  
  <p>Currently I am writing this which is not good :</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>where b is a rectangle.</p>