question: public static void drawCircledText ( Graphics2D g , Font font , String text , int x , int y ) { Graphics2D g2 = ( Graphics2D ) g . create ( ) ; g2 . setFont ( font ) ; FontMetrics fm = g2 . getFontMetrics ( ) ; int padding = 4 ; Rectangle2D bounds = fm . getStringBounds ( text , g2 ) ; double th = bounds . getHeight ( ) ; double tw = bounds . getWidth ( ) ; float radius = ( float ) ( Math . max ( th , tw ) / 2f + padding ) ; Ellipse2D . Float circle = new Ellipse2D . Float ( x - radius , y - radius , 2 * radius + 1 , 2 * radius + 1 ) ; g2 . fill ( circle ) ; g2 . setColor ( Color . BLACK ) ; g2 . drawString ( text , ( int ) ( x - tw / 2 ) , ( y + fm . getAscent ( ) / 2 ) ) ; if ( DEBUG ) { g2 . setColor ( Color . RED ) ; g2 . drawLine ( x - 50 , y , x + 50 , y ) ; g2 . drawLine ( x , y - 50 , x , y + 50 ) ; } g2 . dispose ( ) ; }
target:  Utility function to draw a circle text centered at coordinates (x, y)