import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Font;
import java.awt.FontMetrics;
public class Rogue extends Applet
{
public void paint(Graphics g)
{
Font f = new Font("Monospaced", Font.BOLD, 20);
g.setFont(f);
FontMetrics fontInfo = g.getFontMetrics();
for (int i=0; i<50; i++)
{
for (int j=1; j<=20; j++)
{
g.drawString("A", i * fontInfo.charWidth('A'), j * fontInfo.getHeight() - 1);
}
}
}
}
This is extremely simple. It's ment to just write to an applet of preset size, with characters next to one another in a grid. The characters are horizontally touching as planned, but they have vertical gaps, probably because fontInfo.getHeight() gives a number that's "padded". Is there any way to have a monospaced fond without this vertical padding?
Java monospaced fonts with FontMetrics.getHeight()
Just a quick question with the following code:
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement