question: int breakWord ( String word , FontMetrics fm ) { int width ; int currentPos ; int endPos ; width = 0 ; currentPos = 0 ; endPos = word . length ( ) - 1 ; if ( endPos <= 0 ) { return ( currentPos ) ; } while ( ( width < maxAllowed ) && ( currentPos < endPos ) ) { currentPos ++ ; width = fm . stringWidth ( labelText . substring ( 0 , currentPos ) ) ; } if ( currentPos != endPos ) { currentPos -- ; } return ( currentPos ) ; }
target:  This method scans the input string until the max allowed width is reached. The return value indicates the position just before this happens.