OI gente!!!
Estou com um simples probleminha!!!
Eu estou usando a classe FontMetrics para pegar a altura e a largura da minha String de acordo com o tamanho e a fonte. eu consigo pegar a altura, mas na hora de pegar a largura está dando um erro no método dessa classe. Eu ja tentei usar os métodos stringWidth(String str) e o metodo charsWidth(char []ch, int off, int len), mas está dando erro e eu não estou conseguindo entender. Alguém poderia me ajudar???
Estou mandando um pedaço do meu código…
/********************** Classe SetFont *********************/
private class SetFont extends FontMetrics
{
int height, width;
SetFont(Font font)
{
super(font);
}
public int getHeight()
{
height = super.getHeight();
return height;
}
public int charsWidth(char[] str, int off, int len)
{
width = super.charsWidth(str, off, len);
return width;
}
public int stringWidth(String str)
{
width = super.stringWidth(str);
return width;
}
}
/**************** Fim da Classe SetFont *****************/
/************* Método que escreve a String **************/
private void writeString(String string,int x, int y, int graus, Graphics2D g2)
{
Font font = new Font("Arial", Font.ITALIC, 5);
SetFont fm = new SetFont(font);
g2.setFont(font);
g2.rotate(Math.toRadians(grau),x,y);
g2.drawString(string, x, y);
System.out.println("Altura do texto: "+fm.getHeight());
System.out.println("Largura do texto: " + fm.charsWidth(string.toCharArray(), 0, (string.length()-1)));
}